Login
|
Signup
langref.org
-
ruby
,
csharp
, and
fantom
add..
all
clojure
cpp
erlang
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Maps
Access
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"
ruby
puts "ok" if map.has_key?('mary')
map = {'joe'=>'cat', 'mary'=>'turtle', 'bill'=>'canary'}
puts "ok" if map.has_key?('mary')
ruby
puts "ok" if map['mary'] # Only works if map entry can't be nil or false
map = {'a'=>0, 'b'=>nil, 'c'=>42}
puts "ok" if map['mary'] # Only works if map entry can't be nil or false
fantom
map := ["joe":"cat", "mary":"turtle", "bill":"canary"]
if (map.containsKey("mary")) echo("ok")
class SolutionXX
{
Void main()
{
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
...)