Assuming the Array is sorted I am trying to find the lowest index of a number to be inserted.
When I log the results to the console in the If statement it appears correct.
However, when I try and log the function to the console I get Undefined?
I have tried to declare the function as a var with similar results.
function lowestIndexInsert(num, arrayofIntegers) {
arrayofIntegers.forEach(function(element) {
if(num >= element) {
// console.log(arrayofIntegers.indexOf(element) + 1)
return (arrayofIntegers.indexOf(element) + 1);
}
});
}
var testarray = [1, 3, 5, 6, 7, 11, 13, 50]
console.log(lowestIndexInsert(35, testarray))
This should display the number 7 to the console instead I get undefined.