Tell us what’s happening:
I can’t seem to satisfy the requirement [ getIndexToIns([5, 3, 20, 3], 5)
should return 2
] without completely changing up my code. I wonder if I should just add another ternary if statement?..Any help would be appreciated. Thank you!
Your code so far
function getIndexToIns(arr, num) {
return ((arr.findIndex(n => n >= num)) == -1) ? arr.length
: arr.sort().findIndex(n => n >= num);
}
console.log(getIndexToIns([40, 60], 50));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Safari/605.1.15
.
Challenge: Where do I Belong
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/where-do-i-belong