Created
November 20, 2015 08:09
-
-
Save antoniobeyah/9724e43a9fa20fe82a56 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' | |
describe 'people joining' do | |
it 'has proper return values' do | |
expectations = [ | |
[[''], ''], | |
[['johnny'], "johnny"], | |
[['johnny', 'teddy'], "johnny and teddy"], | |
[['johnny', 'teddy', 'lui'], "johnny, teddy and lui"], | |
[['johnny', 'teddy', 'lui', 'marco'], "johnny, teddy, lui and marco"], | |
] | |
aggregate_failures do | |
expectations.each do |input, expected| | |
actual = friendly(input) | |
expect(actual).to eql(expected) | |
end | |
end | |
end | |
def friendly(array) | |
return array[0] if array.size == 1 | |
ending = array.pop(2).join(' and ') | |
friendly = array[0..array.size-1].push(ending) | |
friendly.join(', ') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment