Skip to content

Instantly share code, notes, and snippets.

View rbishop's full-sized avatar

Richard Bishop rbishop

View GitHub Profile
@rbishop
rbishop / gist:4508218
Last active December 10, 2015 23:18
times table
def times_table number
multiplier = 1
while multiplier <= number
range = (1..number).to_a
row = range.map do |x|
x * multiplier
end
puts row.join(' ')
multiplier += 1
end
@rbishop
rbishop / count_between.rb
Last active December 10, 2015 18:08
Exercise: Count the numbers in an array between a given range Write a method count_between which takes three arguments as input: 1. An Array of integers 2. An integer lower bound 3. An integer upper bound count_between should return the number of integers in the Array between the two bounds, including the bounds It should return 0 if the Array i…
def count_between arr, lower, upper
return 0 if arr.length == 0 || lower > upper
return arr.length if lower == upper
range = (lower..upper).to_a
arr.select { |value| range.include?(value) }.length
end