Skip to content

Instantly share code, notes, and snippets.

@thebyrd
Last active December 21, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebyrd/6228318 to your computer and use it in GitHub Desktop.
Save thebyrd/6228318 to your computer and use it in GitHub Desktop.
var list = [1, 3, 5, 5, 23, 23, 4, 3, 3, 6, 7, 4, 2, 2, 5]
var groups = {}
list.forEach(function (n) {
if (groups[n]) groups[n].push(n)
else groups[n] = [n]
})
var result = []
for (var group in groups) result.push(groups[group])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment