Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Finding the group with largest elements with same digit sum in JavaScript
We are required to write a JavaScript function that takes in a positive integer, say n, as the only argument.
The function should first group the integers from 1 to n to subarray where a specific subarray contains all the elements contains a specific digit sum. Then the function should examine each subarray and return the length of that subarray which contains the most elements.
For example −
If the input number is −
const num = 15;
Then the output should be −
const output = 2;
because the groups are −
[1, 10], [2, 11], [3, 12], [4, 13], [5, 14], [6, 15], [7], [8], [9]
Example
Following is the code −
const num = 67;
const countLargestGroup = (num = 1) => {
if(num Output
Following is the console output −
4
Advertisements
