I don’t get why i had this error: **
getIndexToIns([5, 3, 20, 3], 5) should return 2
**. i mean why would it return 2 if it returns an array [3,5,20] 5 is clearly on index 1
Your code so far
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.push(num); // push the num argument to the array
arr.sort((a,b)=>a-b); // sort the array in ascending order
let newset = [... new Set(arr)]; // create a new set that's free of duplicates and convert it to array
function returnIndex(x){ // find the index of the array element that is equal to the num argument
return x >= num;
}
return newset.findIndex(returnIndex);
}
getIndexToIns([5, 3, 20, 3], 5);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.71 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/where-do-i-belong/