Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

lowest index

//Where do I Belong
//Return the lowest index at which a value (second argument) should be inserted
//into an array (first argument) once it has been sorted. The returned value should be a number.
//For example, getIndexToIns([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1).

function getIndexToIns(arr, num) {
	return arr.filter((val) => num > val).length;
}
 
PREVIOUS NEXT
Tagged: #lowest #index
ADD COMMENT
Topic
Name
4+1 =