Tell us what’s happening:
Describe your issue in detail here.
Where do I Belong. Hi everyone I would some help on why I am unable to pass this challenge with the code I have provided as it outputs the correct answer every time, thanks.
function getIndexToIns(arr, num) {
let arr1 = []
let res = ''
arr.sort(function(a, b) {
return a - b;
});
arr1.push(num)
for (let i = 0; i < arr.length; i++) {
if (arr[i] < num) {
arr1.unshift(arr[i])
} else if (arr[i] > num) {
arr1.push(arr[i])
}
arr1.sort(function(a, b) {
return a - b;
});
}
for (let j = 0; j < arr1.length; j++){
if (arr1[j] === num){
res += j
}
}
return res
}
console.log(getIndexToIns([20,3,5], 19));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36
I’m unsure but I have read it again and it has to return a number so I that’s what the problem it, I just have to figure out how to get my result to return a number not a string. Thanks for replying