January 2020
Intermediate to advanced
532 pages
13h 31m
English
Now that we have the ability to find the top stories and retrieve details about each story, we can create a new function to calculate an average score from the top N stories.
The average_score function is as follows:
using Statistics: meanfunction average_score(n = 10) story_ids = fetch_top_stories() println(now(), " Found ", length(story_ids), " stories") top_stories = [fetch_story(id) for id in story_ids[1:min(n,end)]] println(now(), " Fetched ", n, " story details") avg_top_scores = mean(s.score for s in top_stories) println(now(), " Average score = ", avg_top_scores) return avg_top_scoresend
There are three parts to this function:
Read now
Unlock full access