Skip to content

Instantly share code, notes, and snippets.

@changs
Last active February 27, 2016 15:45
Show Gist options
  • Save changs/f888adc705bfc01aa838 to your computer and use it in GitHub Desktop.
Save changs/f888adc705bfc01aa838 to your computer and use it in GitHub Desktop.
❯ cat flip.rb
require 'benchmark/ips'
DAYS = [:mon, :tue, :wed, :thur, :fri, :sat, :sun]
count = 0
DAYS.each do |day|
if day == :tue .. day == :thur
count += 1
end
end
puts "2-dots: " + count.to_s
count = 0
DAYS.each do |day|
if day == :tue ... day == :thur
count += 1
end
end
puts "3-dots " + count.to_s
count = 0
counting = false
DAYS.each do |day|
if counting
count += 1
if day == :thur
counting = false
end
else
if day == :tue
counting = true
count += 1
end
end
end
puts "Manual: " + count.to_s
~/code
❯ ruby flip.rb
2-dots: 3
3-dots 3
Manual: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment