UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

22 lines (18 loc) 563 B
/** * Works similarly to `Array.prototype.indexOf`, but instead of strict equality - uses provided equality method * @template T * @param {T[]} array * @param {T} element * @param {function(a:T,b:T):boolean} equals * @returns {number} index of first match or -1 if no matches found */ export function array_index_by_equality(array, element, equals) { const n = array.length; for (let i = 0; i < n; i++) { const el = array[i]; if (equals(element, el)) { return i; } } return -1; }