Ruby:
# frozen_string_literal: true require 'json' # Save file as fuel.rb and then run `ruby fuel.rb [7.9,100] [7.0,600]` class FuelConsumption def initialize(before, after) @before = JSON.parse(before) @after = JSON.parse(after) end def calculate trip = @after[1] - @before[1] puts( ((consumed(@after) - consumed(@before)) / trip).round(1) ) end def consumed(data) data[1] * data[0] end end FuelConsumption.new(*ARGV).calculate
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ruby: