Tell us what’s happening:
How do I sort the numbers in the array, .sort won’t work.
How can i get the algorithm to work? I’ve looked for help online to no avail.
thank!
Just need some help understanding why it won’t work and in what instance the sort method would work.
Your code so far
function getIndexToIns(arr, num) {
var array = arr.push(num);
array.sort(function(a, b) {
return a - b;
});
for (var i=0; i<array.length; i++) {
if (array[i] == num) {
return i;
}
}
}
getIndexToIns([40, 60], 50);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 OPR/50.0.2762.67
.
Link to the challenge:
https://www.freecodecamp.org/challenges/where-do-i-belong