You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think for those wondering how to solve the Duplex Redux challenge without using "through", it would be good to add an alternative official solution to compare to.
Here is my solution for the challenge without using "through". I am not sure if the code fulfills latest node and javascript best practices, but it works. It also might be good to point out why solving the challenge with "through" might be preferable to creating a writable stream explicitely on your own.
varspawn=require('child_process').spawnvarStream=require('stream')varduplexer=require('duplexer')module.exports=function(counter){varinwrite=newStream.Writable({objectMode: true})varcountryCounts={}inwrite._write=function(chunk,enc,next){//what to do with the chunkif(countryCounts[chunk.country]){countryCounts[chunk.country]=countryCounts[chunk.country]+1}else{countryCounts[chunk.country]=1}next()}inwrite.on('finish',function(){//in the end: set countryCounts in readable streamcounter.setCounts(countryCounts)})returnduplexer(inwrite,counter)}
The text was updated successfully, but these errors were encountered:
I think for those wondering how to solve the Duplex Redux challenge without using "through", it would be good to add an alternative official solution to compare to.
Here is my solution for the challenge without using "through". I am not sure if the code fulfills latest node and javascript best practices, but it works. It also might be good to point out why solving the challenge with "through" might be preferable to creating a writable stream explicitely on your own.
The text was updated successfully, but these errors were encountered: