@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
22 lines (17 loc) • 559 B
JavaScript
import { assert } from "../../assert.js";
/**
* Adds an element to the end of the array, iff the element is not present in the array already
* @template T
* @param {T[]} array where
* @param {T} element what to add
* @return {boolean} true iff added, false if the array already contains this element
*/
export function array_push_if_unique(array, element) {
assert.isArray(array, 'array');
const i = array.indexOf(element);
if (i === -1) {
array.push(element);
return true;
}
return false;
}