Here is my solution to the problem - where do i belong
There are two things that confuse me about this question:
What purpose does the return arr.length serve? I thought this would just return the length of the original array. Why doesn’t return arr.indexOf(i); work here instead?
If you place the return array.length inside the loop you get different results. I understand that placing the return outside the loop will only return once the loop has finished iterating. How is the arr.length bringing back the correct answer, I thought having the loop break once it found the correct index would be the right call instead, hence putting the return inside the loop.
I added spoiler tags around your code since it is a full working solution.
It is always best to write code directly into the forum instead of posting screenshots.
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 it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.