From b557abdb346e006a969df6684b6c8a8ef2629ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A3=A8=EB=B0=80LuMir?= Date: Sun, 8 Dec 2024 20:40:06 +0900 Subject: [PATCH] wip: create `src/1001.js` --- examples/solutions-readline/src/1001.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/solutions-readline/src/1001.js diff --git a/examples/solutions-readline/src/1001.js b/examples/solutions-readline/src/1001.js new file mode 100644 index 0000000..c3f043f --- /dev/null +++ b/examples/solutions-readline/src/1001.js @@ -0,0 +1,24 @@ +const { createInterface } = require('node:readline'); +const { stdin: input, stdout: output } = require('node:process'); +const { EOL } = require('node:os'); +const { log } = require('node:console'); + +const rl = createInterface({ input, output }); + +let inputFile = ''; + +// eslint-disable-next-line no-shadow +function solution(inputFile) { + const [a, b] = inputFile + .trim() + .split(' ') + .map(val => Number(val)); + + log(a - b); +} + +rl.on('line', line => { + inputFile += `${line}${EOL}`; +}).on('close', () => { + solution(inputFile); +});