Files
30-seconds-of-code/snippets/distinctValuesOfArray.md
Stefan Feješ 82b850fd00 Fix test cases
2017-12-17 22:26:07 +01:00

272 B

distinctValuesOfArray

Returns all the distinct values of an array.

Use ES6 Set and the ...rest operator to discard all duplicated values.

const distinctValuesOfArray = arr => [...new Set(arr)];
// distinctValuesOfArray([1,2,2,3,4,4,5]) -> [1,2,3,4,5]