Tell us what’s happening:
My code for sorting an array with n^2 complexity doesn’t work …what am i doing wrong here ?
Your code so far
function getIndexToIns(arr, num){
let a=[...arr,num];
for(let i=0;i<a.length;a++){
for(let j=0;j<a.length;j++){
if(a[i]>a[j]){
let temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
let ind=a.indexOf(num);
return ind;
}
getIndexToIns([40, 60], 50);
Challenge: Basic Algorithm Scripting - Where do I Belong
Link to the challenge: