Created
January 15, 2015 05:57
-
-
Save falonofthetower/a070637cca20c5a454e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
list = ([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ]) | |
list2 = ([ {name: 'Bart'}, {name: 'Lisa'} ]) | |
list3 = ([ {name: 'Bart'} ]) | |
def transform set | |
names = '' | |
list_length = set.length | |
set.each_with_index do |name, index| | |
if index + 2 == list_length | |
name[:name].insert(-1, " & ") | |
elsif index + 1 != list_length | |
name[:name].insert(-1, ", ") | |
end | |
names << name[:name] | |
end | |
puts names | |
end | |
transform list | |
transform list2 | |
transform list3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment