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
import { calculateAverageScore } from 'https://raw.githubusercontent.com/minnacaptain/have-you-tried-deno-yet/master/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), | |
); |
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
import { assertEquals } from "https://deno.land/std@0.102.0/testing/asserts.ts"; | |
import { calculateAverageScore } from './calculate.ts' | |
const mockGetContent = () => Promise.resolve( | |
"student_name,horoscope,exam_name,exam_score,feedback_score,would_recommend\n" + | |
"Braylen Natalia,Gemini,AWS Certified Cloud Practitioner,1,4.26,Yes\n" + | |
"Kash Macey,Leo,AWS Certified SysOps Administrator,2,3.04,Yes\n" + | |
"Erica Daniela,Sagittarius,AWS Certified Cloud Practitioner,3,7.61,Yes" | |
) |
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
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; | |
}); |
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 getContentFromInternet = () => | |
fetch( | |
"https://raw.githubusercontent.com/minnacaptain/have-you-tried-deno-yet/master/example_data.txt", | |
).then((t) => t.text()); | |
// calculateAverageScore is unchanged | |
console.log("Average score: " + await calculateAverageScore(getContentFromInternet)); |
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 | |
}) |
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(",")) | |
console.log(lines) | |
}) | |
calculateAverageScore(getContent) |