Skip to content

Instantly share code, notes, and snippets.

@chalu
Created July 18, 2019 17:26
Show Gist options
  • Select an option

  • Save chalu/b027009ecdad6d92be9c21580c775cbb to your computer and use it in GitHub Desktop.

Select an option

Save chalu/b027009ecdad6d92be9c21580c775cbb to your computer and use it in GitHub Desktop.
const match = (field, delegate) => {
return (data = []) => {
return data.filter(entry => delegate(entry[field]));
}
};
const isMale = (value) => value === 'male';
const isFemale = (value) => value === 'female';
const getMales = match('gender', isMale);
const getFemales = match('gender', isFemale);
const males = getMales(data);
const females = getFemales(data);
console.log(`we've got ${females} femalse and ${males} males`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment