📜  最低索引 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:30.592000             🧑  作者: Mango

代码示例1
//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;
}