Created
March 7, 2017 04:47
-
-
Save itzsaga/1ed118c35bfa43ca62b44c5e5759496f 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
def oxford_comma(array) | |
if array.length == 1 | |
return "#{array[0]}" | |
elsif array.length == 2 | |
return array.join(" and ") | |
elsif array.length >= 3 | |
array[-1] = "and #{array[-1]}" | |
return array.join(", ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment