Skip to content

Instantly share code, notes, and snippets.

@ekrem-aktas
Created September 24, 2020 12:19
Show Gist options
  • Save ekrem-aktas/28024690f5a75811f072b75e53aee422 to your computer and use it in GitHub Desktop.
Save ekrem-aktas/28024690f5a75811f072b75e53aee422 to your computer and use it in GitHub Desktop.
function groupBy(arr, func){
let grouped = Object.create(null);
arr.forEach((item) => {
const key = func(item);
if (!grouped[key]) {
grouped[key] = [];
}
grouped[key].push(item);
});
return grouped;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment