Skip to content

Instantly share code, notes, and snippets.

@radiodario
Last active August 29, 2015 14:01
Show Gist options
  • Save radiodario/065dfefe7a53a2ba80e9 to your computer and use it in GitHub Desktop.
Save radiodario/065dfefe7a53a2ba80e9 to your computer and use it in GitHub Desktop.
Juttle Fizzbuzz

YOU'RE HIRED.

var d3 = require('d3');
var buzzer = {
initialize: function(options) {
},
consume: function(batch) {
this.container.prepend('<h3>' + batch[0].result + '</h3>' );
}
};
register_sink('buzzer', buzzer);
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