Created
February 8, 2019 18:33
-
-
Save robertoandres24/61c2e46fff83be5fcda594fde54b56cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var groupBy = function(xs, key) { | |
return xs.reduce(function(rv, x) { | |
(rv[x[key]] = rv[x[key]] || []).push(x); | |
return rv; | |
}, {}); | |
}; | |
console.log(groupBy(['one', 'two', 'three'], 'length')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment