Answers for "removing duplicates from array in javascript with good time complexity"

4

how to remove duplicates in array in javascript

const numbers = [1 , 21, 21, 34 ,12 ,34 ,12];
const removeRepeatNumbers = array => [... new Set(array)]
removeRepeatNumbers(numbers) // [ 1, 21, 34, 12 ]
Posted by: Guest on September-25-2020
0

how to remove duplicates from array in javascript

// how to remove duplicates from array in javascript
// 1. filter()
let num = [1, 2, 3, 3, 4, 4, 5, 5, 6];
let filtered = num.filter((a, b) => num.indexOf(a) === b)
console.log(filtered);
// Result: [ 1, 2, 3, 4, 5, 6 ]

// 2. Set()
const removeDuplicates = (arr) => [...new Set(arr)];
console.log(removeDuplicates([1, 2, 3, 3, 4, 4, 5, 5, 6]));
// Result: [ 1, 2, 3, 4, 5, 6 ]
Posted by: Guest on January-07-2022

Code answers related to "removing duplicates from array in javascript with good time complexity"

Code answers related to "Javascript"

Browse Popular Code Answers by Language