Suppose I have an array like [1,1,2,2,3,4]
I want to get [3,4] by using a function like function answer(data,n)
Suppose I have an array like [1,1,2,2,3,4]
I want to get [3,4] by using a function like function answer(data,n)
I would reduce()
down to a map with the elements as keys, and boolean values to indicate whether the element has been seen before. Then it's just a matter of filtering out the entries that are duplicates:
const data = [1, 1, 2, 2, 3, 4];
const result = [
...data.reduce((a, v) => a.set(v, a.has(v)), new Map())
].filter(([_, v]) => !v).map(([k]) => k);
console.log(result);