View Problem
Create a histogram map from a list
Given the list
Submit a new solution for ruby, erlang, cpp, fantom ...
There are 25 other solutions in additional languages (clojure, csharp, go, groovy ...)
[a,b,a,c,b,b], produce a map {a:2, b:3, c:1} which contains the count of each unique item in the list
fsharp
let histogram list =
let rec histogram' list' dict' =
match list' with
| [] -> dict'
| x :: xs ->
match Map.tryFind x dict' with
| Some(Value) -> histogram' xs (Map.add x (Value + 1) dict')
| None -> histogram' xs (Map.add x 1 dict')
histogram' list Map.empty
// ------
let histogram' = histogram list
let rec histogram' list' dict' =
match list' with
| [] -> dict'
| x :: xs ->
match Map.tryFind x dict' with
| Some(Value) -> histogram' xs (Map.add x (Value + 1) dict')
| None -> histogram' xs (Map.add x 1 dict')
histogram' list Map.empty
// ------
let histogram' = histogram list
Submit a new solution for ruby, erlang, cpp, fantom ...
There are 25 other solutions in additional languages (clojure, csharp, go, groovy ...)




