Created
May 22, 2016 00:06
-
-
Save depeele/22e94e904a8ea9e4ef8fd0e78f0209ad to your computer and use it in GitHub Desktop.
HackerRank Javascript stdin using an ES6 generator
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
'use strict'; | |
function* Lines( stream ) { | |
const EOL = require('os').EOL; | |
const Fs = require('fs'); | |
const buf = new Buffer(1); | |
while( true ) { | |
const chars = []; | |
while (Fs.readSync(stream.fd, buf, 0, buf.length)) { | |
let str = buf.toString(); | |
if (str === EOL) { break; } | |
chars.push( str ); | |
} | |
if (chars.length < 1) { break; } | |
yield chars.join(''); | |
} | |
} | |
const lines = Lines( process.stdin ); | |
for (let T = 0, end = parseInt( lines.next().value ); T < end; T++) { | |
let N = parseInt( lines.next().value ); | |
// Do your work here (or replace this loop entirely) | |
console.log("%d", N); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment