Skip to content

Instantly share code, notes, and snippets.

@chalu
Created July 18, 2019 17:06
Show Gist options
  • Save chalu/8a071f0157e2a1db8f44718e3ad9c957 to your computer and use it in GitHub Desktop.
Save chalu/8a071f0157e2a1db8f44718e3ad9c957 to your computer and use it in GitHub Desktop.
const computed = data.reduce((sum, {age = 0}, index) => {
const value = sum + age;
if(index === data.length-1) return value / data.length;
return value;
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment