• Removes duplicates from an array of numbers or strings.

    Example

    const arr1 = [1, 2, 3, 2, 1]
    uniq(arr1)
    // => { ok: true, value: [1, 2, 3] }

    const arr2 = ['apple', 'banana', 'cherry', 'banana', 'apple']
    uniq(arr2).value
    // => { ok: true, value: ['apple', 'banana', 'cherry'] }

    Example

    Handle an invalid input:

    uniq('not an array')
    // => { ok: false, value: error: Error('[collections.uniq] Input is not an array') }

    Type Parameters

    • T extends string | number

      The type of the elements in the input array.

    Parameters

    • arr: T[]

      The array to remove duplicates from.

    Returns Result<T[], Error>

    A Result object with either an array with the duplicates removed, or an Error object if the provided input is not an array.

Generated using TypeDoc v0.24.7