Return the lowest index at which a value
function getIndexToIns(arr, num) {
return arr.filter(val => num > val).length;
}
Return the lowest index at which a value
function getIndexToIns(arr, num) {
return arr.filter(val => num > val).length;
}
Return the lowest index at which a value
function getIndexToIns(arr, num) {
return arr
.concat(num)
.sort((a, b) => a - b)
.indexOf(num);
}
getIndexToIns([1, 3, 4], 2);
Return the lowest index at which a value
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;
}
Return the lowest index at which a value
function getIndexToIns(arr, num) {
// sort and find right index
let index = arr
.sort((curr, next) => curr - next)
.findIndex(currNum => num <= currNum);
// Returns index or total length of arr
return index === -1 ? arr.length : index;
}
getIndexToIns([40, 60], 500);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us