Skip to content

Instantly share code, notes, and snippets.

@minnacaptain
Created July 23, 2021 12:53
Show Gist options
  • Save minnacaptain/3692ead6e297e45bd7d6ab34c4256cef to your computer and use it in GitHub Desktop.
Save minnacaptain/3692ead6e297e45bd7d6ab34c4256cef to your computer and use it in GitHub Desktop.
calculate.ts
export 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;
});
import { calculateAverageScore } from './calculate.ts'
const getContentFromInternet = () =>
fetch(
"https://raw.githubusercontent.com/minnacaptain/have-you-tried-deno-yet/master/example_data.txt",
).then((t) => t.text());
console.log(
"Average score: " + await calculateAverageScore(getContentFromInternet),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment