Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created November 22, 2015 09:37
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 chuck0523/9da08acbcdcf60b9e5da to your computer and use it in GitHub Desktop.
Save chuck0523/9da08acbcdcf60b9e5da to your computer and use it in GitHub Desktop.
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