Following is my code in which is working fine for smaller array number, but if I am using large size number of array in the method it is giving weird answers -
Code -
function upArray(arr){
var fail = false,
count = '';
arr.map(function(x){
if(x>10 || x<0 || x== null || x== undefined)
fail = true;
else {
count += x.toString();
fail = false;
}
})
if(arr.length < 1)
fail = true;
return fail ? null : (parseInt(count)+1).toString().split("").map(function(x){return parseInt(x);});
}
Correct result -
console.log(upArray([2,4,5])); //[2,4,6]
console.log(upArray([2,5,1])); //[2,5,2]
console.log(upArray([2,8,9])); //[2,9,0]
BUT - If I am giving a large array of numbers, its giving weird results -
like -
console.log(upArray([9,2,2,3,3,7,2,0,3,6,8,5,4,7,7,5,8,0,8]));
giving - [9, 2, 2, 3, 3, 7, 2, 3, 6, 8, 5, 4, 7, 7, 5, 8, 0]
Let me know what I am doing wrong over here and what is the fix ?