ngx-bootstrap
Version:
Angular Bootstrap
29 lines • 963 B
JavaScript
/**
* Returns the index of the last element in the array where predicate is true, and -1
* otherwise.
* @param array The source array to search in
* @param predicate find calls predicate once for each element of the array, in descending
* order, until it finds one where predicate returns true. If such an element is found,
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
*/
export function findLastIndex(array, predicate) {
let l = array.length;
while (l--) {
if (predicate(array[l], l, array)) {
return l;
}
}
return -1;
}
export function chunkByNumber(array, size) {
const out = [];
const n = Math.ceil((array.length) / size);
let i = 0;
while (i < n) {
const chunk = array.splice(0, (i === n - 1) && size < array.length ? array.length : size);
out.push(chunk);
i++;
}
return out;
}
//# sourceMappingURL=utils.js.map