Last active
August 29, 2015 14:01
-
-
Save radiodario/065dfefe7a53a2ba80e9 to your computer and use it in GitHub Desktop.
Juttle Fizzbuzz
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
var d3 = require('d3'); | |
var buzzer = { | |
initialize: function(options) { | |
}, | |
consume: function(batch) { | |
this.container.prepend('<h3>' + batch[0].result + '</h3>' ); | |
} | |
}; | |
register_sink('buzzer', buzzer); |
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
var i = 0; | |
var HZ = 1; | |
var FINISH = 100; | |
var str = ''; | |
var f = 0; | |
var $now = Date.now(); | |
function fizzbuzz() { | |
i = i + 1; | |
str = ""; | |
f = 0; | |
if (i % 3 == 0) { | |
str = "fizz"; | |
f = f + 1; | |
} | |
if (i % 5 == 0 && f > 0) { | |
str = str + "buzz"; | |
f = f + 1; | |
} | |
if (i % 5 == 0 && f == 0) { | |
str = "buzz"; | |
f = f + 1; | |
} | |
if (f > 0) { | |
return str; | |
} | |
return i; | |
} | |
emitter -hz HZ -limit FINISH -start $now | |
| pacer | |
| put result=fizzbuzz(), number=i | |
| @buzzer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment