Last active
May 25, 2019 13:15
-
-
Save kofoworola/a0520704d1f4c526030c5002013c69c4 to your computer and use it in GitHub Desktop.
Hotjar code sample
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 filterAndGroup(people){ | |
//Add empty object to offset it | |
people.unshift({}) | |
//Use reduce method to loop through and sort | |
return people.reduce((grouped,obj) => { | |
//Gender of current item | |
const gender = obj.gender; | |
//Check age requirement | |
if(obj.age >= 30 && obj.age <= 40) | |
{ | |
//Append this perso to the accumulators array of this gender | |
grouped[gender] = (grouped[gender] || []).concat(obj); | |
} | |
//return accumulator | |
return grouped; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment