Skip to content

Instantly share code, notes, and snippets.

@antoniobeyah
Created November 20, 2015 08:09
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 antoniobeyah/9724e43a9fa20fe82a56 to your computer and use it in GitHub Desktop.
Save antoniobeyah/9724e43a9fa20fe82a56 to your computer and use it in GitHub Desktop.
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