RosettaCodeData/Task/Search-a-list/Groovy/search-a-list.groovy
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

13 lines
477 B
Groovy

def haystack = ["Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"]
def needles = ["Washington","Bush","Wally"]
needles.each { needle ->
def index = haystack.indexOf(needle)
def lastindex = haystack.lastIndexOf(needle)
if (index < 0) {
assert lastindex < 0
println needle + " is not in haystack"
} else {
println "First index: " + index + " " + needle
println "Last index: " + lastindex + " " + needle
}
}