Skip to content

Instantly share code, notes, and snippets.

@jgimbel
Created June 26, 2017 20:55
Show Gist options
  • Save jgimbel/fae63651c0f329b417f8a3c4b1c0eb83 to your computer and use it in GitHub Desktop.
Save jgimbel/fae63651c0f329b417f8a3c4b1c0eb83 to your computer and use it in GitHub Desktop.
const numbers = [ 1, 2, 3, 5, 7, 22, 34, 56, 234]
const average = numbers.reduce(runningAverage)
function runningAverage (average, current, idx) {
return (average * idx + current) / (idx + 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment