-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsampleRefCode.js
39 lines (33 loc) · 899 Bytes
/
sampleRefCode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const readline = require('readline');
// Function to read multi-line input
function readInput() {
return new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const lines = [];
rl.on('line', (input) => {
if (input.trim() === 'END') {
rl.close(); // End input collection
} else {
lines.push(input); // Add input to the array
}
});
rl.on('close', () => {
resolve(lines); // Resolve the promise with collected lines
});
});
}
// Main function to use the input
async function main() {
try {
const inputLines = await readInput();
console.log('Processing input:');
console.log(inputLines.join('\n')); // Process the input as needed
} catch (error) {
console.error('An error occurred:', error);
}
}
// Call the main function
main();