Where do I belong , stuck in one condition

Tell us what’s happening:
Describe your issue in detail here.
Hello coders :)) can someone tell me why this specific line doesnt work in the following code.
else if (newArr == ) {
return 0;

  **Your code so far**

function getIndexToIns(arr, num) {
let newArr = [...arr];
for (let j=0; j < arr.length; j++) {
 for (let k=0; k < arr.length; k++) {
   if (newArr[k] > newArr[j]) {
     let kvalue = newArr[k];
     let jvalue = newArr[j];
     newArr[k] = jvalue;
     newArr[j] = kvalue;
 }
}
}
console.log(newArr);
for (let i = 0; i < newArr.length; i++) {
  if (num > newArr[i] && num < newArr[i+1]) {
      return i+1;
  }
  else if (num == newArr[i]) {
    return i;
  }
  else if (newArr == []) {
    return 0;
  }
  else if (num > newArr[arr.length-1]) {
    return arr.length;
  }
}
return num;
}

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/92.0.4515.107 Safari/537.36 Edg/92.0.902.62

Challenge: Where do I Belong

Link to the challenge:

1 Like

So you have that line inside a for loop that is looping from 0 to newArr.length times. What do you suppose the length of [] might be?

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.