Examples
Write unique so that the following cases hold.
- Input
unique([1,2,2,3,1])Output[1,2,3] - Input
unique([])Output[] - Input
unique(["a","a","b"])Output["a","b"]
Answer
text
function unique(arr) {
return [...new Set(arr)];
}
unique([1, 2, 2, 3, 1]); // [1, 2, 3]
