@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
24 lines (19 loc) • 602 B
JavaScript
/**
* Remove first occurrence of element from the array
* @template T
* @param {T[]} array
* @param {T} element
* @param {number} [start_index]
* @param {number} [length]
* @return {boolean} true if element was removed, false if it was not found
*/
export function array_remove_first(array, element, start_index = 0, length = array.length) {
const end_index = start_index + length;
for (let i = start_index; i < end_index; i++) {
if (array[i] === element) {
array.splice(i, 1);
return true;
}
}
return false;
}