Created
October 8, 2011 14:34
-
-
Save MaximeD/1272356 to your computer and use it in GitHub Desktop.
many ways
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| array=[1,2,0,3,3,5,0,4] | |
| value_to_search = 3 | |
| total = 0 | |
| # ruby one-line | |
| array.each { |value| total += 1 if value == value_to_search} | |
| # ruby multiple | |
| array.each do |value| | |
| total += 1 if value == value_to_search | |
| end | |
| # ruby in a perlish-way | |
| array.each { |value| | |
| total +=1 if value == value_to_search | |
| } | |
| # silly stuff | |
| array.each do |value| total=+1 if value == value_to_search end | |
| puts "\"#{value_to_search}\" is #{total} time(s) in array" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment