A
A
asmodeus13th2021-06-18 18:08:07
JavaScript
asmodeus13th, 2021-06-18 18:08:07

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

2 answer(s)
0
0xD34F, 2021-06-18
@0xD34F

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])

A
aloky, 2021-06-18
@aloky

new Set?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question