Tell us what’s happening:
I have been trying this single line method that should have worked but I can’t figure out why the “else if()” statement won’t return anything except -1.
**Your code so far**
// bellow is the code that I'd submitted:
arr.sort( (a, b) => {return a - b});
for (var i = 0; i < arr.length; i++) {
if (arr[i] >= num) return i;
}
return arr.length;
// it ends here
// this is the code I was working on...
return arr.sort( (a,b) =>{return a - b}).findIndex((value,index,array) =>{if (value >= num){return index;}else if(index >= array.length){return array.length} });
// it ends here
function getIndexToIns(arr, num) {
return arr.sort( (a,b) =>{return a - b}).findIndex((value,index,array) =>{
if (value >= num){
return index;
}else if(index >= array.length){
return array.length
}
});
}
getIndexToIns([2, 15, 10], 15);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
.
Challenge: Where do I Belong
Link to the challenge: