Created
December 25, 2018 08:53
-
-
Save zgfif/dd478ec499303d47d3326e2733a5320b to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
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