Skip to content

Instantly share code, notes, and snippets.

@zgfif
Created December 25, 2018 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgfif/dd478ec499303d47d3326e2733a5320b to your computer and use it in GitHub Desktop.
Save zgfif/dd478ec499303d47d3326e2733a5320b to your computer and use it in GitHub Desktop.
require 'rspec'
require 'rspec/its'
require_relative 'task_seven'
RSpec.describe TaskSeven do
let(:array) { [5, -3, 3, -5, 6, 6, 6, -1, 0, 2] }
subject { described_class.new array }
its(:number_elements_after_max) { should eq 3 }
end
class TaskSeven
def initialize array
@array = array
end
def number_elements_after_max
max_index = 0
max_value = @array[0]
@array.each_with_index do |value, index|
if max_value <= value
max_value = value
max_index = index
end
end
@array.count - max_index - 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment