Tell us what’s happening:
Hello all! I have a question regarding the process of calling a function, inside of a function. Where I get confused is what arguments get passed in. Below I have the resolution code for the problem, “Where do I Belong”, where they want you to return the index value of the array, where “num” would fit. The code makes sense for the most part; however, I get a bit lost when I try to imagine what is being passed in as “a” and “b” in the code: arr.sort(function(a,b){return a-b;}); Would “arr” and “num” be the passed arguments into the function(a,b)? Several problems have been throwing me off, the deeper I get into “function-ception”. Any feedback/guidance to better under this concept is much appreciated.
Your code so far
function getIndexToIns(arr, num) {
arr.sort(function(a,b){return a-b;});
for (let i = 0; i < arr.length; i++){
if (arr[i] >= num)
return parseInt(i);
}
return arr.length;
}
console.log(JSON.stringify(getIndexToIns([10, 20, 30, 40, 50], 35)));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
.
Link to the challenge: