Skip to content

Commit cdcaeb6

Browse files
authored
Create removeDuplicates.js
1 parent 7bd0e97 commit cdcaeb6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Array/removeDuplicates.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const fruits = ['🥑', '🍊', '🍇', '🍏', '🍎', '🍑', '🍑'];
2+
3+
// way 1
4+
console.log('way 1 ', fruits.reduce((uniqueArray, fruit) => {
5+
uniqueArray.indexOf(fruit) === -1 && uniqueArray.push(fruit);
6+
return uniqueArray;
7+
}, []))
8+
9+
// way 2
10+
console.log('way 2 ', fruits.filter((fruit, index) => fruits.indexOf(fruit) === index))
11+
12+
// way 3
13+
console.log('way 3 ', [...new Set(fruits)])

0 commit comments

Comments
 (0)