Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jonathanrodriguezs
Last active June 21, 2020 23:12
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 jonathanrodriguezs/0af14d1118983d8c0fa80f3e722442b5 to your computer and use it in GitHub Desktop.
Save jonathanrodriguezs/0af14d1118983d8c0fa80f3e722442b5 to your computer and use it in GitHub Desktop.
Group by lodash's replica
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