# Thread: Adding 1 in to each of array with Separators in javascript

1. ## Adding 1 in to each of array with Separators in javascript

Adding 1 to each in array from 1 to 15 maximum.
with Numeric Separators .

Code:
```var n = "11_11_11_11_11_11_11_11_11_11";
var maxNum = "15";
var separator = "_";

return result.join("_");
}```

Result
Code:
```... "11_11_11_11_11_11_11_11_11_12"
... "11_11_11_11_11_11_11_11_11_13"
... "11_11_11_11_11_11_11_11_11_14"
... "11_11_11_11_11_11_11_11_11_15"
... "11_11_11_11_11_11_11_11_12_1"
... "11_11_11_11_11_11_11_11_12_2"
... "11_11_11_11_11_11_11_11_12_3"```
Is it possible to add a large numbers with Separators ?

2. ## Re: Adding 1 in to each of array with Separators in javascript

Split function puts the string into an array.

Join turns the array back into a string.

The rest of the logic seems quite simple - and maybe even recursive. Do you need to see finished code?

What have you got so far?

3. ## Re: Adding 1 in to each of array with Separators in javascript

Hi

Code:
```var n = "11_11_11_11_11_11_11_11_11_11";
var maxNum = "15";
var separator = "_";

n = n.split(separator).reverse();
let maxLen = n.length;
let sum = [];
let remainder = 0;

for (let i = 0; i < maxLen; i++) {
let x = parseInt(a[i]) ? parseInt(a[i]) : 0;
let digit = (x + remainder);
remainder = Math.floor((x + remainder));
sum.unshift(digit);
}
if (remainder) {sum.unshift(remainder)}

return sum.join("_");
//return sum.filter(n => { return n; } ).join('_');
}```
I have tried this function but it's not count up ...

4. ## Re: Adding 1 in to each of array with Separators in javascript

@optikal - did you solve this yet?

5. ## Re: Adding 1 in to each of array with Separators in javascript

Hi szlamany ,thank you for your attention.

I am working hard to solve it.
But It's not working yet with this function too
It's seems very very difficult...

Code:
```function addNum(arr, separator, maxNum) {
arr = arr.split(separator).reverse();
let maxLen= Math.max(arr.length);
let sum = [];
let remainder = 0;
for (let i = 0; i < maxLen; i++) {
let x = parseInt(arr[i]) ? parseInt(arr[i]) : 0;
let digit = (x + remainder) % 10;
remainder = Math.floor((x + remainder) / 10);
sum.unshift(digit);
}
if (remainder) {sum.unshift(remainder)}

return sum.join("");
//return sum.filter(n => { return n; } ).join('-');
}```

6. ## Re: Adding 1 in to each of array with Separators in javascript

This works for me:

Code:
```function addNum(n, separator, maxNum, addone) {
n = n.split(separator).reverse();
let maxLen = n.length;
let sum = [];
let max = parseInt(maxNum, 10);

for (let i = 0; i < maxLen; i++) {
let x = parseInt(n[i]) ? parseInt(n[i]) : 0;
let digit = (x + remainder);
if (digit > max) {
digit = 1;
remainder = 1;
} else {
remainder = 0;
}
sum.unshift(digit);
}

return sum.join("_");
}```
Tested with this loop

Code:
```function testNum() {

var n = "11_11_11_11_11_11_11_11_11_11";
var maxNum = "15";
var separator = "_";

for (var i = 0; i < 100; i++) {
}

}```
Cool code to write - thanks for the exercise!

7. ## Re: Adding 1 in to each of array with Separators in javascript

BOOOM Thats it szlamany.
Cool