Where i belong; I don´t know if this code is ok for the problem any advice?

function getIndexToIns(arr, num) {
let count = 0;
for (let i = 0; i < arr.length; i++)
if (arr[i] < num) {
return count;

getIndexToIns([40, 60], 50);

Hello and welcome!

First. You can try to edit your post and press ctrl-e. You will see how to make your code look more readable.

Second. We don’t know, for what purpose this code is. Please provide challenge step link if it’s from freeCodeCamp curriculum.

If not, describe the problem. What this code should do?

1 Like

Looks good to me!

Since you have no need for the index variable i, you could use a for…of loop to make this a little more readable.

for (const val of arr) {
  if (val < num) {

it’s just checking how many elements are smaller than num, that doesn’t rely on order

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