Happy New Year Challenge – Code Fights

By December 31, 2015 No Comments

So I joined this new website ‘Code Fights‘ which has some very exciting challenges, one of which is the following “Happy New Year Challenge”. The gist of it is as following:

After finishing your last CodeFight of 2015 you suddenly realize: the New Year is almost here! To share your excitement, you want to send a New Year’s wish to the community.

You think your message should look nice, so you decide to put it into a frame of asterisks ('*'), with each word on a separate line.

Write a function that returns a framed wish as an array of strings, where each string is a word of the wish (including any punctuation marks that might come right after it) with some spaces added to make the frame rectangular. Note that there should be exactly 1 whitespace character (' ') before each word, and at least 1 after.


For wish = 'Happy New Year and CodeFight On in 2016!' the output should be

happyNewYear(wish) = ['*************', 
                      '* Happy     *', 
                      '* New       *', 
                      '* Year      *', 
                      '* and       *', 
                      '* CodeFight *', 
                      '* On        *', 
                      '* in        *', 
                      '* 2016!     *', 
  • [input] string wish
    • Your wish that has at least one word.
  • [output] array.string
    • The framed version of your wish

So here is my solution for the above problem:

Credit for the creation of Problem: Code Fights


Author Naveen

A Computer Science graduate student, a programmer, photographer, reader and blogger

More posts by Naveen

Leave a Reply