UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

30 lines (23 loc) 720 B
/** * @template T * @param {T[]} source * @param {number} [start_index] first index to be included in the search * @param {number} [end_index] last index to be included in the search * @return {boolean} */ export function array_contains_duplicates( source, start_index = 0, end_index = source.length - 1 ) { // going to n-1, as we check all elements forward from the current const last = end_index - 1; for (let k = start_index; k <= last; k++) { const element = source[k]; // look for future occurrences of the same element if (source.indexOf(element, k + 1) !== -1) { return true; } } return false; }