"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dedupe = exports.flat = void 0;
/**
 * A shim for the `flat()` method that creates a new array with all sub-array
 * elements concatenated into it recursively up to the specified depth
 * @param arr - The array.
 * @param depth - The depth level specifying how deep a nested array
 *                struction should be flattened. Defaults to 1.
 * @returns A new array with the sub-array elements concatenated to it.
 */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function flat(arr, depth = 1) {
    // implementation taken from
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat#Alternative
    return depth > 0
        ? arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flat(val, depth - 1) : val), [])
        : arr.slice();
}
exports.flat = flat;
/**
 * Deduplicates an array's element. Note that order is not preserved.
 * @param arr - The array.
 * @returns A new array containing only unique elements.
 */
function dedupe(arr) {
    return Array.from(new Set(arr));
}
exports.dedupe = dedupe;
