@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
21 lines (17 loc) • 420 B
JavaScript
/**
* @template T
* @param {T[]} array
* @param {T} victim
* @param {T} replacement
* @returns {T[]} input array after replacements
*/
export function array_replace_all(array, victim, replacement) {
const n = array.length;
for (let i = 0; i < n; i++) {
const el = array[i];
if (el === victim) {
array[i] = replacement;
}
}
return array;
}