DEV Community

Discussion on: Write better code: Day 1 - Apple Stock Prices

Collapse
 
delbetu profile image
M Bellucci • Edited

In ruby

possible_trades = stock_prices.combination(2).to_a
max_trade_index = possible_trades.map { |x,y| y-x }.each_with_index.max[1]
return possible_trades[max_trade_index]