DEV Community

Discussion on: Daily Challenge #35 - Find the Outlier

Collapse
 
mwlang profile image
Michael Lang

Ruby Language

With specs!

def outlier values
  o = values.partition(&:odd?).sort_by(&:size)[0]
  o[0] if o.size == 1
end

require "spec"

describe "#name_shuffler" do
  it { expect(outlier [2, 4, 0, 100, 4, 11, 2602, 36]).to eq 11}
  it { expect(outlier [160, 3, 1719, 19, 11, 13, -21]).to eq 160}
  it { expect(outlier [4, 8, 15, 16, 24, 42]).to eq 15}
  it { expect(outlier [16, 6, 40, 66, 68, 28]).to eq nil}
end

output

>> rspec outlier.rb
....

Finished in 0.0052 seconds (files took 0.15152 seconds to load)
4 examples, 0 failures