It seems that I am missing something. Can someone help?
Thanks
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.push(num);
arr.sort();
console.log(arr.indexOf(num));
return arr.indexOf(num);
}
It seems that I am missing something. Can someone help?
Thanks
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.push(num);
arr.sort();
console.log(arr.indexOf(num));
return arr.indexOf(num);
}
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
Thank You @camperextraordinaire.
…
Solved:
unction getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.unshift(num);
arr.sort(function(a,b){
return a - b;
});
console.log(arr.indexOf(num));
return arr.indexOf(num);
}