Given an empty pets map, add the mapping from
"rob" to
"dog"
ruby pets['rob']='dog'
pets = []
pets['rob']='dog'
clojure (assoc {} 'rob 'dog)
(assoc {} 'rob 'dog)
fsharp pets <- (Map.add "rob" "dog" pets)
#light
open System
open System.Collections
let mutable pets = Map.empty
pets <- (Map.add "rob" "dog" pets)
for pet in pets do printfn "%s -> %s" (pet.Key) (pet.Value) done
fsharp pets.Add("rob", "dog")
#light
open System
open System.Collections
let pets = new Generic.Dictionary<string, string>()
pets.Add("rob", "dog")
for pet in pets do printfn "%s -> %s" (pet.Key) (pet.Value) done
Submit a new solution for
ruby,
clojure, or
fsharp
There are 18 other solutions in
additional languages (
cpp,
erlang,
fantom,
go ...)