Skip to content

Instantly share code, notes, and snippets.

@chuck0523

chuck0523/io03.js

Created Nov 22, 2015
Embed
What would you like to do?
var
lines = [],
sum = 0,
head = '加算したい数値を入力してください。';
END = 'end',
readline = require('readline').createInterface(process.stdin, process.stdout);
var
log = function(str) { console.log(str); },
end = function(str) { return str === END; },
parseInt10 = function(num) { return parseInt(num, 10); },
logSum = function(sum, str) { log('合計は' + sum + str); };
log(head);
readline.on('line', function(line) {
if(end(line)) {
logSum(sum, 'でした。');
process.exit(0);
}
sum += parseInt10(line);
logSum(sum, 'です。');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment