Skip to content

Instantly share code, notes, and snippets.

@kofoworola
Last active May 25, 2019 13:15
Show Gist options
  • Save kofoworola/a0520704d1f4c526030c5002013c69c4 to your computer and use it in GitHub Desktop.
Save kofoworola/a0520704d1f4c526030c5002013c69c4 to your computer and use it in GitHub Desktop.
Hotjar code sample
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