Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Last active December 15, 2018 13:18
Show Gist options
  • Save joe-oli/559684a1af67018a691ff2dd63bb4555 to your computer and use it in GitHub Desktop.
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
//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