Created
September 24, 2020 12:19
-
-
Save ekrem-aktas/28024690f5a75811f072b75e53aee422 to your computer and use it in GitHub Desktop.
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 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