I'm facing a challenge with arrays that I can't seem to resolve. My goal is to locate numbers that are not part of the array. The function should only return a value if it's not already in the array, otherwise, it should increment the value (to ensure no duplicates).
Here's how my code looks:
function create_number(number) {
var array = [1,2,3,6,7,8,9];
for (var i=0;i<array.length;i++) {
if (array[i] == number) {
return number;
} else {
// generate a new number that doesn't exist in the array and return it.
}
// If not found, repeat the loop.
// If no match is found after looping through, generate a valid number
// that is not included in the array.
}
}