Skip to content

Instantly share code, notes, and snippets.

@minnacaptain
Created July 23, 2021 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minnacaptain/dd1c2bba09105da18805f2d6ff16cc82 to your computer and use it in GitHub Desktop.
Save minnacaptain/dd1c2bba09105da18805f2d6ff16cc82 to your computer and use it in GitHub Desktop.
Calculate the average score
const getContent = () => Deno.readTextFile('./example_data.txt')
const calculateAverageScore = (getContent: () => Promise<string>) => getContent().then(result => {
const lines = result.split("\n")
.map(l => l.split(","))
.filter((_, i) => i !== 0)
const scores = lines.map(l => Number(l[3]))
return scores.reduce((a, c) => a + c) / scores.length
})
console.log("Average score: " + await calculateAverageScore(getContent))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment