12 days of christmas Code kata

I found a nice seasonal challenge for the end of the year - printing out the lyrics to the '12 Days of Christmas':
On the first day of Christmas, 
my true love gave to me,
A partridge in a pear tree.
On the second day of Christmas, 
my true love gave to me,
Two turtle doves, 
And a partridge in a pear tree.
...
On the twelfth day of Christmas,
My true love gave to me,
Twelve drummers drumming,
Eleven pipers piping,
Ten lords-a-leaping,
Nine ladies dancing,
Eight maids-a-milking,
Seven swans-a-swimming,
Six geese-a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.
Rules
  • You don't have to worry about capitalization; the entire text can be case insensitive
  • You can sensibly ignore any punctuation: hyphens can be spaces, and commas and periods can be ignored
  • There should be a blank line between each verse
  • You must ordinalize your numbers: "first day of Christmas", "Four calling birds", etc

Here is my submission

4 comments:

  1. Here's my shot at it:
    https://gist.github.com/jhixson/7294fb508ebb2e578906
    You can run it with babel-node or paste in into the Babel repl.

    ReplyDelete
  2. Here's an ES6/Node version.
    https://github.com/n3dst4/twelve-days-of-xmas-kata/blob/master/src/twelve-days-of-xmas-kata.js
    Can install with
    npm install @n3dst4/twelve-days-of-xmas-kata@latest -g
    and run with
    n3dst4-twelve-days-of-xmas-kata
    There's a test too, if you rummage round the repository.

    ReplyDelete
  3. Hi! I really enjoyed this exercise. I'm also looking forward to sharing it with my class. We'll be starting a unit on JavaScript early in the new year, and this is a great (and timely) exercise for discussing the different constructs for iteration available in JS.

    Anyway, here's my (Node) implementation: https://gist.github.com/jnf/5a39cb016e511c44c98e
    My goal was to make it testable, so I extracted mots of the logic bits into functions. The `verse` function produces the text for a single day, and the `sing` function sings the whole song. Thanks!

    ReplyDelete
    Replies
    1. Thanks! Glad you enjoyed my post!
      I like your implementation!
      I meant to TDD mine, but I didn't have the time as I did most of it on my lunch break in work! It was a bit of festive fun though!

      Delete