Calculate the average score
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
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