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