Created
April 2, 2015 19:11
-
-
Save octosteve/84971547b492da5ed822 to your computer and use it in GitHub Desktop.
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
require 'pry' | |
students = File.readlines('students') | |
# students.each do |student| | |
# puts "#{student.chomp} is a member of The Flatiron School" | |
# end | |
# | |
students.each do |student| | |
if student.start_with?('S') | |
puts student.strip | |
end | |
end | |
# | |
# students.each {|student| puts student.chomp } | |
def students_counter(students_array, count) | |
students_array.first(count).each do |student| | |
puts "You asked for #{count} students" | |
puts "#{student.chomp} is a member of The Flatiron School" | |
end | |
end | |
# | |
students_counter(students, 5) |
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
students = [ | |
"Cassidy Robertson", | |
"Ian Valentine", | |
"Dana Najjar", | |
"Lucy Orbach", | |
"Findlay Parke", | |
"Jahde Eve", | |
"Ben Gadbaw", | |
"Franco Mendoza", | |
"Kenny Miyasato", | |
"Parker Lawrence", | |
"Jonathan Meyers", | |
"Waruna Perera", | |
"Abeille Abejorro", | |
"Summer Min", | |
"Chad Ruble", | |
"Adam Czerepinski", | |
"Evan Schrager", | |
"Seph Kramer", | |
"Timothy Murray", | |
"Simone Hill", | |
"Josh Baker", | |
"Julian Taub", | |
"Evan Rosse", | |
"Jonathan Tow", | |
"Dace Willmott", | |
"Hannah Westheimer", | |
"Stefania Sicurelli" | |
] | |
students.each.with_object([]) do |student, collection| | |
if student.start_with?('D') | |
collection << "#{student}" | |
end | |
end | |
# => ["Dana Najjar", "Dace Willmott"] |
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
require 'pry' | |
students = File.readlines('students') | |
i = 0 | |
loop do | |
puts "#{students[i].chomp} is a member of The Flatiron School" | |
i += 1 | |
break if i == students.length | |
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
students = File.readlines('students') | |
def my_each(array) | |
i = 0 | |
while i < array.size | |
if array[i].start_with?('J') | |
yield(array[i]) | |
end | |
i += 1 | |
end | |
array | |
end | |
# my_each(students) do |element| | |
# puts "I got yielded element #{element.chomp}" | |
# end | |
my_each(students) do |element| | |
puts "I got yielded element #{element.chomp}" | |
end | |
# | |
# def gimme_double(num) | |
# puts "you gave me #{num}" | |
# doubled = num * 2 | |
# if block_given? | |
# result = yield(doubled) | |
# puts "The block returned #{result}" | |
# end | |
# end | |
# | |
# gimme_double(7) do |number| | |
# number | |
# end | |
# def square_numbers(numbers) | |
# i = 0 | |
# while i < numbers.count | |
# puts numbers[i] * numbers[i] | |
# i += 1 | |
# end | |
# end | |
# | |
# def double_numbers(numbers) | |
# i = 0 | |
# while i < numbers.count | |
# puts numbers[i] * 2 | |
# i += 1 | |
# end | |
# end | |
# | |
# [1,2,3].each do |num| | |
# puts num * num | |
# end | |
# | |
# [1,2,3].each do |num| | |
# puts num - num | |
# 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
require 'pry' | |
students = File.readlines('students') | |
students.each do |student| | |
changed = true | |
end | |
if changed | |
puts "I was changed in the block" | |
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
Cassidy Robertson | |
Ian Valentine | |
Dana Najjar | |
Lucy Orbach | |
Findlay Parke | |
Jahde Eve | |
Ben Gadbaw | |
Franco Mendoza | |
Kenny Miyasato | |
Parker Lawrence | |
Jonathan Meyers | |
Waruna Perera | |
Abeille Abejorro | |
Summer Min | |
Chad Ruble | |
Adam Czerepinski | |
Evan Schrager | |
Seph Kramer | |
Timothy Murray | |
Simone Hill | |
Josh Baker | |
Julian Taub | |
Evan Rosse | |
Jonathan Tow | |
Dace Willmott | |
Hannah Westheimer | |
Stefania Sicurelli |
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
require 'pry' | |
students = File.readlines('students') | |
# i = 0 | |
# while i < students.length | |
# puts "#{students[i].chomp} is a member of The Flatiron School" | |
# i += 1 | |
# end | |
def students_counter(students_array, count) | |
# i = 0 | |
# while i < count | |
while count.nonzero? | |
puts "#{students_array[count - 1].chomp} is a member of The Flatiron School" | |
count -= 1 | |
end | |
end | |
students_counter(students, 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment