Created
January 11, 2018 10:18
-
-
Save fractalatcarf/5b334aabe1a4f8ec6a3aebc6febd92c6 to your computer and use it in GitHub Desktop.
morning code
This file contains 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
# def timer | |
# start_time = Time.now | |
# yield | |
# puts "Elapsed time: #{Time.now - start_time}s" | |
# end | |
# # def timer2 | |
# # start_time = Time.now | |
# # (1..8000000).to_a.each {|n|} | |
# # puts "Elapsed time: #{Time.now - start_time}s" | |
# # end | |
# # result = timer do |message| | |
# # puts message | |
# # sleep(2) | |
# # end | |
# # puts result | |
# puts "how many iterations" | |
# count = gets.chomp.to_i | |
# result = timer do | |
# (1..count).to_a.each {|n|} | |
# end | |
# puts result | |
def say_hello(first_name, last_name) | |
full_name = "#{first_name} #{last_name}" | |
puts yield(full_name) if block_given? | |
end | |
say_hello("Charles", "Brownson") | |
say_hello("Johnny", "Hallyday") do |name| | |
"Hi #{name}" | |
end |
This file contains 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
musicians = ['David Gilmour', 'Roger Waters', 'Richard Wright', 'Nick Mason'] | |
# for index in (0...musicians.length) | |
# puts "#{index} - #{musicians[index]}" | |
# end | |
# for musician in musicians | |
# puts musician | |
# end | |
# musicians.each_with_index do |musician, index| | |
# puts "#{index} - #{musician}" | |
# end | |
# puts "=" * 20 | |
count = 0 | |
musicians.each do |musician| | |
# count += 1 | |
count = count + 1 | |
cont + 1 | |
puts "#{count} - #{musician}" | |
end | |
# a = 3 | |
musicians = ['David Gilmour', 'Roger Waters', 'Richard Wright', 'Nick Mason'] | |
# upcased_musicians = [] | |
# musicians.each do |musician| | |
# upcased_musicians << musician.upcase | |
# end | |
# p upcased_musicians | |
# upcased_musicians = musicians.map do |musician| | |
# musician.upcase | |
# end | |
# # strictly equivalent to | |
# upcased_musicians = musicians.map { |musician| musician.upcase } | |
# p upcased_musicians | |
# filtering =========================== | |
# filtered_musicians = [] # contains only musicians with 1st letter is "R" | |
# musicians.each do |musician| | |
# if musician[0] == "R" | |
# filtered_musicians << musician | |
# end | |
# # filtered_musicians << musician if musician[0] == "R" | |
# end | |
# p filtered_musicians | |
# filtered_musicians = musicians.select do |musician| | |
# musician[0] == "R" | |
# end | |
# p filtered_musicians | |
# figures = (0..200).to_a | |
# even_figures = figures.select do |figure| | |
# figure.even? | |
# end | |
# p even_figures | |
# # counting =============================== | |
# counter = 0 | |
# musicians.each do |musician| | |
# counter += 1 if musician[0] == "R" | |
# end | |
# p counter | |
counter = musicians.count do |musician| | |
musician[0] == "R" | |
end | |
counter = musicians.count { |musician| musician[0] == "R" } | |
puts counter | |
def say_hi(name) | |
return "Hi #{name} !!" | |
end | |
do |name| | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment