function getIndexToIns(arr, num) {
// Find my place in this sorted array.
let sorted = arr.sort((a,b) => a - b);
console.log(sorted);
for(let x in sorted){
if(sorted[x] >= num){
return x;
}
}
return sorted.length;
}
I wonder If anyone can tell me why this code doesn’t work. BTW I know that a simple for loop works and just want to learn why this one does not work FCC but works on Atom. Thanks!
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.
Note: Backticks are not single quotes.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
I moved your question to a new topic, because you were asking about your own solution and not commenting or providing feedback to the original poster of the other thread.