sequence: 1,2,3,…10
formula: x = n+1
suppose sequence is an array and at a given time sequence contain 1,3,5 on first three indexes remaining contain 0
now next number should be 2 and array will have 1,2,3,5 on first four indexes remaining contain 0
now next number should be 4 and array will have 1,2,3,4,5 on first five indexes remaining contain 0
now next number should be 6 and array will have 1,2,3,5,6 on first six indexes remaining contain 0
function findNextNumber(numArry) {
var number = 1;
var tempArray = new Array();
for (i = 0; i < 10; i++) {
tempArray[i] = "E";
}
$.each(numArry, function () {
if (this != 0) {
tempArray[this] = "F"
}
});
$.each(tempArray, function (index) {
if (this == "E") {
number = index + 1;
return false;
}
});
return number;
}
1 Answer