Remove Duplicates v3

Remove Duplicates v3

Given an array find and remove Duplicates

Example
let arr1 = [1, 1, 2, 3, 3, 100, 3, 7, -4]; => [ 1, 2, 3, 100, 7, -4 ] let arr2 = [‘Hi’, ‘Hello’, ‘Hi’, ‘Hey’,’Hi’]; => [ ‘Hi’, ‘Hello’, ‘Hey’ ]

function removeDuplicates(arr) {
 return [...new Set(arr)];
}

console.log(removeDuplicates(arr1))
console.log(removeDuplicates(arr2))

We create function called removeDuplicates with parameter arr

We use Set functions to remove duplicates

***return[…new Set(arr)];

comments powered by Disqus