Skip to content

Instantly share code, notes, and snippets.

@alaz
Forked from depeele/gist:66656a73bf53773ae852f6613ae05876
Last active January 7, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaz/501e5a9e4166c3aa9b4ae399018dcf93 to your computer and use it in GitHub Desktop.
Save alaz/501e5a9e4166c3aa9b4ae399018dcf93 to your computer and use it in GitHub Desktop.
HackerRank Javascript stdin using an ES6 generator and larger buffer
'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