需求
查找num在arr中升序排序的索引
getIndexToIns([2, 20, 10], 19) should return 2
function getIndexToIns(arr, num) {
var index = arr.sort((a, b) => a - b)
.findIndex(a => num <= a);
return index === -1 ? arr.length : index;
}
getIndexToIns([40, 60], 500);
噜噜哒
相关分类