Last active
August 29, 2015 14:07
-
-
Save adregan/56ef6a27803bb7621152 to your computer and use it in GitHub Desktop.
This file contains 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
module.exports = function(counter) { | |
var duplexer = require('duplexer') | |
, through = require('through') | |
, thr = through(write) | |
, countries = {} | |
; | |
return duplexer(thr, counter); | |
function write(buf) { | |
if (countries.hasOwnProperty(buf.country)) { | |
countries[buf.country] += 1; | |
} | |
else { | |
countries[buf.country] = 1; | |
} | |
} | |
function end(buf) { | |
counter.setCounts(countries); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment