Skip to content

Instantly share code, notes, and snippets.

@ootoovak
Created May 14, 2014 03:05
Show Gist options
  • Save ootoovak/0d0cabf916befc162de6 to your computer and use it in GitHub Desktop.
Save ootoovak/0d0cabf916befc162de6 to your computer and use it in GitHub Desktop.
require 'pry'
require 'pry-byebug'
def get_even_numbers_from_zero_to(number)
numbers = []
(0..9).each do |number|
numbers << number if (number % 2 == 0)
end
return numbers
end
def look_for(number, numbers)
found = -1
numbers.each_with_index do |array_number, index|
found = index if array_number == number
end
return found
end
def print_found(number, index)
# binding.pry # You can use this anywhere in this program to pause and explore things like variables. Try it out.
if index >= 0
puts "Found number #{number} at index #{index}!"
else
puts "Did not find the number #{number} in the array. :("
end
end
def find_number(number, numbers)
found_at_index = look_for(number, numbers)
print_found(number, found_at_index)
end
numbers = get_even_numbers_from_zero_to(9)
find_number(3, numbers)
find_number(6, numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment