Forked from depeele/gist:66656a73bf53773ae852f6613ae05876
Last active
January 7, 2017 16:00
-
-
Save alaz/501e5a9e4166c3aa9b4ae399018dcf93 to your computer and use it in GitHub Desktop.
HackerRank Javascript stdin using an ES6 generator and larger buffer
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
'use strict'; | |
function* readLine(stream) { | |
const EOL = require('os').EOL; | |
const Fs = require('fs'); | |
const buf = new Buffer(1024); | |
stream.resume(); | |
stream.setEncoding('ascii'); | |
while (Fs.readSync(stream.fd, buf, 0, buf.length)) { | |
let lines = buf.toString().split(EOL); | |
if (lines.length < 1) { | |
break; | |
} | |
for (let index in lines) { | |
yield lines[index]; | |
} | |
} | |
} | |
let reader = readLine(process.stdin); | |
let a = parseInt(reader.next().value); | |
let b = parseInt(reader.next().value); | |
console.log(a+b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment