Removes duplicates from an array of numbers or strings.
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'] } Copy
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'] }
Handle an invalid input:
uniq('not an array')// => { ok: false, value: error: Error('[collections.uniq] Input is not an array') } Copy
uniq('not an array')// => { ok: false, value: error: Error('[collections.uniq] Input is not an array') }
The type of the elements in the input array.
The array to remove duplicates from.
A Result object with either an array with the duplicates removed, or an Error object if the provided input is not an array.
Result
Error
Generated using TypeDoc v0.24.7
Removes duplicates from an array of numbers or strings.
Example
Example
Handle an invalid input: