Posted By

luizlopes on 11/18/11


Tagged

javascript String buzz exercise fizzbuzz fizz


Versions (?)

Elegant FizzBuzz Example


 / Published in: JavaScript
 

URL: http://ricardo.cc/2011/06/02/10-CoffeeScript-One-Liners-to-Impress-Your-Friends.html

When you use the + operator on an Array, it converts it to a string.[].toString() is the same as [].join(','), which gives an empty string in case the array value is undefined or null. This also works in Javascript ([undefined] + "b" === "b").

  1. var i;
  2.  
  3. for (i = 1; i <= 100; i++) {
  4. console.log([!(i % 3) ? 'fizz' : void 0] + [!(i % 5) ? 'buzz' : void 0] || i);
  5. }

Report this snippet  

You need to login to post a comment.