View Problem

Check if a key exists in a map

Given a map pets {joe:cat,mary:turtle,bill:canary} print "ok" if an pet exists for "mary"
ExpandDiskEdit
ruby
puts "ok" if map.has_key?('mary')
ExpandDiskEdit
ruby
puts "ok" if map['mary'] # Only works if map entry can't be nil or false
ExpandDiskEdit
fantom
map := ["joe":"cat", "mary":"turtle", "bill":"canary"]
if (map.containsKey("mary")) echo("ok")

Submit a new solution for ruby, csharp, or fantom
There are 25 other solutions in additional languages (clojure, cpp, erlang, fsharp ...)