From http://www.codewars.com/dojo/katas/5258b272e6925db09900386a/solutions/javascript