Answer the question
In order to leave comments, you need to log in
How to clear an array of duplicate elements?
Essence of the question. Write a function that takes an array and returns an array with elements that are not repeated. An array can be made up of numbers, strings, and booleans. The speed of the function should be no more than O(n) .
Result. I pass [2, 5, 8, 2, true, 5, 2] to the function and get [8, true] .
Answer the question
In order to leave comments, you need to log in
Array
.from(arr.reduce((acc, n) => acc.set(n, (acc.get(n) ?? 0) + 1), new Map))
.filter(n => n[1] === 1)
.map(n => n[0])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question