Last active
June 22, 2019 02:45
-
-
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.
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 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