Skip to content

Commit

Permalink
Merge pull request #43 from cassiosantana/release/0.7
Browse files Browse the repository at this point in the history
Release/0.7
  • Loading branch information
cassiosantana authored May 1, 2023
2 parents 543155a + 7723967 commit a615f84
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
algorithms_ruby (0.6.0)
algorithms_ruby (0.7.0)

GEM
remote: https://rubygems.org/
Expand All @@ -11,7 +11,7 @@ GEM
ffaker (2.21.0)
json (2.6.3)
parallel (1.23.0)
parser (3.2.2.0)
parser (3.2.2.1)
ast (~> 2.4.1)
rainbow (3.1.1)
rake (13.0.6)
Expand All @@ -21,9 +21,9 @@ GEM
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.1)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.5)
Expand Down
1 change: 1 addition & 0 deletions lib/algorithms_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require_relative 'algorithms_ruby/version'
require_relative 'algorithms_ruby/missing_character'
require_relative 'algorithms_ruby/linear_search'
require_relative 'algorithms_ruby/find_three'

module AlgorithmsRuby
class Error < StandardError; end
Expand Down
22 changes: 22 additions & 0 deletions lib/algorithms_ruby/find_three.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module AlgorithmsRuby
class FindTree
def self.find(arr)
first = second = third = 0
arr.size.times do |i|
if arr[i] > first
third = second
second = first
first = arr[i]
elsif arr[i] > second and arr[i] != first
third = second
second = arr[i]
elsif arr[i] > third and arr[i] != second and arr[i] != first
third = arr[i]
end
end
[first, second, third]
end
end
end
2 changes: 1 addition & 1 deletion lib/algorithms_ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module AlgorithmsRuby
VERSION = '0.6.0'
VERSION = '0.7.0'
end
14 changes: 14 additions & 0 deletions spec/algorithms_ruby/find_three_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

RSpec.describe AlgorithmsRuby do
describe 'FindTree' do
context 'random array' do
let(:arr) { 5.times.map { FFaker::Random.rand(0..9) } }
let(:result) { AlgorithmsRuby::FindTree.find(arr) }

it 'the three largest non-repeating numbers' do
expect(result).to eq(arr.uniq.max(3))
end
end
end
end

0 comments on commit a615f84

Please sign in to comment.