381 B
381 B
Unique values of array
use ES6 Set and the ...rest operator to discard all duplicated values.
const unique = c => [...new Set(c)]
// unique([1,2,2,3,4,4,5]) -> [1,2,3,4,5]
Use Array.filter for an array containing only the unique values
const unique = c => c.filter(i => c.indexOf(i) === c.lastIndexOf(i))
// unique([1,2,2,3,4,4,5]) -> [1,3,5]