Skip to content

Instantly share code, notes, and snippets.

@NicolasFrancaX
Created September 27, 2016 11:55
Show Gist options
  • Save NicolasFrancaX/60ed06bb8b4badfa5bc90c80f7d79286 to your computer and use it in GitHub Desktop.
Save NicolasFrancaX/60ed06bb8b4badfa5bc90c80f7d79286 to your computer and use it in GitHub Desktop.
function packLists(a) {
if (!a.length) {
return [[]];
} else if (a.length == 1) {
return [[a[0]]];
}
var c = [a[0]]
, b = [c]
, k = 0;
for (var i = 1; i < a.length; i++) {
if (a[i] != a[i - 1]) {
k++;
b.push([]);
}
b[k].push(a[i]);
}
return b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment