Last active
December 15, 2018 13:18
-
-
Save joe-oli/559684a1af67018a691ff2dd63bb4555 to your computer and use it in GitHub Desktop.
unique elements in a Set (by definition) or making Array elements unique
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//immutable: | |
const { List } = require('immutable'); | |
const someList = List([1,2,3,4,4,4,4]); | |
const uniqueList = someList.toSet(); | |
//ES6: | |
const someArr = [1,2,3,4,4,4,4]; | |
const uniqueSet = new Set(someArr); //==> {1,2,3,4} uniqueSet.constructor is a Set; typeof uniqueSet = "object" | |
const uniqueArr = [...uniqueSet]; //==> [1,2,3,4] uniqueList.constructor is an Array; typeof uniqueList = "object" | |
const uniqueArr2 = Array.from(uniqueSet); //ALT to above line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment