Use Array.prototype.find

This commit is contained in:
Tim Schaub
2022-07-27 13:57:35 -06:00
parent f2d989b299
commit 157bdc5208
5 changed files with 9 additions and 70 deletions

View File

@@ -168,25 +168,6 @@ export function remove(arr, obj) {
return found;
}
/**
* @param {Array<VALUE>} arr The array to search in.
* @param {function(VALUE, number, ?) : boolean} func The function to compare.
* @template VALUE
* @return {VALUE|null} The element found or null.
*/
export function find(arr, func) {
const length = arr.length >>> 0;
let value;
for (let i = 0; i < length; i++) {
value = arr[i];
if (func(value, i, arr)) {
return value;
}
}
return null;
}
/**
* @param {Array|Uint8ClampedArray} arr1 The first array to compare.
* @param {Array|Uint8ClampedArray} arr2 The second array to compare.