Last active
June 21, 2020 23:12
-
-
Save jonathanrodriguezs/0af14d1118983d8c0fa80f3e722442b5 to your computer and use it in GitHub Desktop.
Group by lodash's replica
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
function groupped (list, param) { | |
return list.reduce((result, item) => { | |
let prop = item[param] | |
const hasProp = result.hasOwnProperty(prop) | |
if(hasProp) result[prop].push(item) | |
else result[prop] = [item] | |
return result | |
}, {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment