Created
December 29, 2020 09:28
-
-
Save acobster/76d656c3e266e012dfccf43946f8589d to your computer and use it in GitHub Desktop.
Oxford Comma
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
(defn oxford-comma [phrases] | |
(if (> (count phrases) 2) | |
(join ", and " [(join ", " (butlast phrases)) (last phrases)]) | |
(join " and " phrases))) | |
(oxford-comma []) ;; => "" | |
(oxford-comma ["one"]) ;; => "one" | |
(oxford-comma ["one" "two"]) ;; => "one and two" | |
(oxford-comma ["one" "two" "three"]) ;; => "one, two, and three" | |
(oxford-comma ["one" "two" "three" "four"]) ;; => "one, two, three, and four" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment