-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuniqueChars.js
More file actions
28 lines (23 loc) · 794 Bytes
/
uniqueChars.js
File metadata and controls
28 lines (23 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function filterUnique(arr) {
let mySet = new Set()
const x = arr.map((a) => {
console.log(a)
return mySet.add(a)
console.log(mySet)
})
console.log(x)
return x
}
// console.log(filterUnique(['abb', 'abc', 'abcdb', 'aea', 'bbb'])) // ➞ ["abc"]
// // "b" occurs in "abb" more than once, "b" occurs in "abcdb" more than once, etc.
// console.log(filterUnique(['88', '999', '989', '9988', '9898'])) // ➞ []
// console.log(filterUnique(['ABCDE', 'DDEB', 'BED', 'CCA', 'BAC'])) // ➞ ["ABCDE", "BED", "BAC"]
// let mySet = new Set()
// mySet.add(1) // Set [ 1 ]
// console.log(mySet)
// mySet.add(5) // Set [ 1, 5 ]
// console.log(mySet)
// mySet.add(5) // Set [ 1, 5 ]
// console.log(mySet)
// mySet.add('some text') // Set [ 1, 5, 'some text' ]
// console.log(mySet)