Last active
August 29, 2015 14:04
-
-
Save mrdougwright/792d7dcb992d832dafe6 to your computer and use it in GitHub Desktop.
Apple Stock
This file contains hidden or 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
arr = [20,30,50,40,100,10,45,95,30,10] | |
def low_high(stock_prices) | |
max = 0 | |
stock_prices.each_with_index do |x, index| | |
current_max = 0 | |
stock_prices[index..-1].each do |y| | |
current_max = y - x | |
if current_max > max | |
max = current_max | |
low = x | |
high = y | |
end | |
end | |
end | |
puts "low num: #{low} high num: #{high}" | |
end | |
low_high(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment