Skip to content

Instantly share code, notes, and snippets.

@AndrewYatzkan
Last active June 22, 2019 02:45
Show Gist options
  • Save AndrewYatzkan/93da3c1fc86359d49ddf0b5b91de7cbf to your computer and use it in GitHub Desktop.
Save AndrewYatzkan/93da3c1fc86359d49ddf0b5b91de7cbf to your computer and use it in GitHub Desktop.
Find the average rating on a scale of 1-N given an array of numbers.
function averageRating(arr) {
return arr.reduce((a,c,i)=>a+c*(i+1))/arr.reduce((a,c)=>a+c);
}
// example: averageRating([12, 234, 456, 767, 566]) => 3.8...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment