new files

This commit is contained in:
Ingy döt Net 2013-04-10 12:38:42 -07:00
parent 3af7344581
commit 86c034bb8b
1364 changed files with 21352 additions and 0 deletions

View file

@ -0,0 +1,9 @@
haystack = %w(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo)
%w(Bush Washington).each do |needle|
if (i = haystack.index(needle))
print i, " ", needle, "\n"
else
raise "#{needle} is not in haystack\n"
end
end

View file

@ -0,0 +1,7 @@
haystack.each do |item|
last = haystack.rindex(item)
if last > haystack.index(item)
puts "#{item} last appears at index #{last}"
break
end
end

View file

@ -0,0 +1,3 @@
multi_item = haystack .each_with_index .group_by {|elem, idx| elem} .find {|key, val| val.length > 1}
# multi_item is => ["Bush", [["Bush", 4], ["Bush", 7]]]
puts "#{multi_item[0]} last appears at index #{multi_item[1][-1][1]}" unless multi_item.nil?