Created
November 21, 2018 21:26
-
-
Save BrutalSimplicity/5f47ed1a81b900287f1ef9c04e2df266 to your computer and use it in GitHub Desktop.
One of our restaurant clients wants to know which pizza topping combinations are the most popular. Write a throw-away .NET console application that will download orders directly from http://files.olo.com/pizzas.json and output the top 20 most frequently ordered pizza topping combinations. List the toppings for each popular pizza topping combinat…
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
open FSharp.Data | |
type Pizza = JsonProvider<"pizzas.json"> | |
type ToppingFrequencyPair = { Toppings: string[]; Frequency: int } | |
let getToppingFrequencyPair grouping = | |
{ Toppings = fst grouping; Frequency = snd grouping |> Array.length } | |
[<EntryPoint>] | |
let main argv = | |
let bestToppings = | |
Pizza.Load "http://files.olo.com/pizzas.json" | |
|> Array.groupBy (fun x -> x.Toppings |> Array.sort) | |
|> Array.map getToppingFrequencyPair | |
|> Array.sortByDescending (fun x -> x.Frequency) | |
|> Array.take 20 | |
bestToppings |> Array.map (fun x -> printfn "%A" x) |> ignore | |
0 // return an integer exit code |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<Compile Include="Program.fs" /> | |
</ItemGroup> | |
<ItemGroup> | |
<PackageReference Include="FSharp.Data" Version="3.0.0" /> | |
</ItemGroup> | |
</Project> |
Author
BrutalSimplicity
commented
Nov 21, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment