Skip to content

Instantly share code, notes, and snippets.

@nkhil
Created April 10, 2020 12:46
Show Gist options
  • Save nkhil/8c4980d91e16e9bd415e9014ef2e6edf to your computer and use it in GitHub Desktop.
Save nkhil/8c4980d91e16e9bd415e9014ef2e6edf to your computer and use it in GitHub Desktop.
const property = obj[key];
// obj[key] here will be '1991'.
acc[property] = acc[property] || [];
// At this point acc['1991'] doesn't yet exist, so it will be an empty array. This step is important as it checks if acc['1991'] exists, and if not, creates it and assigns a value of an empty array.
acc[property].push(obj);
// Here, all we're doing is pushing our object into the right group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment