Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

filter array and get index of num

function getIndexToIns(arr, num) {
  arr.sort((a, b) => a - b);

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] >= num)
      return i;
  }

  return arr.length;
}
Source by forum.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #filter #array #index #num
ADD COMMENT
Topic
Name
1+6 =