This week's challenge is the first a series of cross-backend technology challenges (JVM, .NET, Ruby, and PHP). Code can be submitted in any language, and each submission will only be graded against like-languaged submissions.
First, some background: The oxford comma is a type of comma that is employed when there are more than two items in a list. It is also the source of countless pretentious debates.
This week's challenge is to create a set of methods that do two things: remove oxford commas from a string, and add oxford commas to a string.
class Oxfordinator
{
public function AddOxfordCommas($input);
public function RemoveOxfordCommas($input);
}
Example input strings:
- I like flour, sugar and chocolate in my brownies.
- My peripherals include headphones, keyboards and mice.
- Our presidents, Lady and Tom O'Neill.
- They went to the Nerdery with Joe, a client and an employee.
Winners will be selected using a secret input that we will keep hidden. The individual who adds the most correct commas to the input, while having the least errors, will be selected.
Here are the sentences I used for input for testing each submission (with commas):
## Original set of examples
1.1. I like flour, sugar, and chocolate in my brownies.
1.2. My peripherals include headphones, keyboards, and mice.
1.3. Our presidents, Lady, and Tom O'Neill.
1.4. They went to the Nerdery with Joe, a client, and an employee.
## Some tricky ones because of characters
2.1. Clients love things like earth-dwellers, fish-mongers, and derelict space stations.
2.2. They had 45 guns, 14 tanks, and 100 flutes.
2.3. Do not post on the following sites: Instagram, Google+, and Facebook.
2.4. He arrived carrying a book, a sack and/or bowl, and a feather.
2.5. I remember sites like Dogpile, Yahoo!, and Altavista.
2.6. She was sure to include things like a lamp, the @ symbol, and matches.
2.7. Avoid variable names like $foo, $bar, and $baz.
2.8. The following things are trending: Clinton, #blessed, and Star Wars.
2.9. We like band names like NiN, 50%, and Journey.
2.10. How about sixty-five, one (1), and forty-four?
2.11. I can't handle checkers, "lol," and words like 'sluice.'
2.12. She listens to country, rock & roll, and big band.
2.13. Can you do math problems like 1+1, 2+2, and 4+4?
2.14. And in LaTeX syntax like $5$, \infty, and \section.
2.15. But only using HTML elements like <embed>, <blink>, and <iframe>.
2.16. Keep track of things like tabs,spaces, and escape codes.
2.17. They were Gary, Dr. Smith, and Suzanne.
2.18. The presentation included things like a=a, =>, and nil.
2.19. Then he typed "ruby has no bare words," "def method_missing(*args); args.join(" "); end;", and "ruby has bare words."
2.20. But what about Bob, Judy, or Larry?
2.21. I haven't seen rain, snow, nor clouds.
## Some tricky ones because of words
3.1. The only things I care about are umbrellas, large genetically modified hybrid dinosaurs, and chess.
3.2. I would like to propose, not because I am mean, but for various reasons here and there, that from now on and forever, humans and fairies eat only chicken, cheese, broccoli, potatoes, horseradish, beets, prunes, and pork chops.
3.3. You mentioned phrases like "Time is Money," "The man with shoes, pipes, and dreams," and "With great power comes great responsibility."
And the sentences without commas:
## Original set of examples
1.1. I like flour, sugar and chocolate in my brownies.
1.2. My peripherals include headphones, keyboards and mice.
1.3. Our presidents, Lady and Tom O'Neill.
1.4. They went to the Nerdery with Joe, a client and an employee.
## Some tricky ones because of characters
2.1. Clients love things like earth-dwellers, fish-mongers and derelict space stations.
2.2. They had 45 guns, 14 tanks and 100 flutes.
2.3. Do not post on the following sites: Instagram, Google+ and Facebook.
2.4. He arrived carrying a book, a sack and/or bowl and a feather.
2.5. I remember sites like Dogpile, Yahoo! and Altavista.
2.6. She was sure to include things like a lamp, the @ symbol and matches.
2.7. Avoid variable names like $foo, $bar and $baz.
2.8. The following things are trending: Clinton, #blessed and Star Wars.
2.9. We like band names like NiN, 50% and Journey.
2.10. How about sixty-five, one (1) and forty-four?
2.11. I can't handle checkers, "lol" and words like 'sluice.'
2.12. She listens to country, rock & roll and big band.
2.13. Can you do math problems like 1+1, 2+2 and 4+4?
2.14. And in LaTeX syntax like $5$, \infty and \section.
2.15. But only using HTML elements like <embed>, <blink> and <iframe>.
2.16. Keep track of things like tabs,spaces and escape codes.
2.17. They were Gary, Dr. Smith and Suzanne.
2.18. The presentation included things like a=a, => and nil.
2.19. Then he typed "ruby has no bare words," "def method_missing(*args); args.join(" "); end;" and "ruby has bare words."
2.20. But what about Bob, Judy or Larry?
2.21. I haven't seen rain, snow nor clouds.
## Some tricky ones because of words
3.1. The only things I care about are umbrellas, large genetically modified hybrid dinosaurs and chess.
3.2. I would like to propose, not because I am mean, but for various reasons here and there, that from now on and forever, humans and fairies eat only chicken, cheese, broccoli, potatoes, horseradish, beets, prunes and pork chops.
3.3. You mentioned phrases like "Time is Money," "The man with shoes, pipes and dreams" and "With great power comes great responsibility."