diff options
| author | Abigail <abigail@abigail.be> | 2021-01-22 20:28:00 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-22 20:28:00 +0100 |
| commit | d3b7070aceb66209460753b95438b7e53f07bd61 (patch) | |
| tree | 2ca123b78f05ab23d20f7e52b97bf63cc7bdf878 | |
| parent | 674232e2c4cc94045c30259726508a1296976f5e (diff) | |
| download | perlweeklychallenge-club-d3b7070aceb66209460753b95438b7e53f07bd61.tar.gz perlweeklychallenge-club-d3b7070aceb66209460753b95438b7e53f07bd61.tar.bz2 perlweeklychallenge-club-d3b7070aceb66209460753b95438b7e53f07bd61.zip | |
Use the 'readline' module instead of the 'fs' module to read lines.
| -rwxr-xr-x | challenge-096/abigail/node/ch-1.js | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/challenge-096/abigail/node/ch-1.js b/challenge-096/abigail/node/ch-1.js index 15aa190086..994c1e1971 100755 --- a/challenge-096/abigail/node/ch-1.js +++ b/challenge-096/abigail/node/ch-1.js @@ -8,15 +8,10 @@ // Run as: node ch-1.js < input-file // - require ("fs") -. readFileSync (0) // Read all. -. toString () // Turn it into a string. -. split ("\n") // Split on newlines. -. filter (_ => _ . length) // Filter out empty lines. -. map (_ => console . log (_ . trim () // Remove leading - // and trailing - // whitespace. - . split (/\s+/) // split ... - . reverse () // reverse ... - . join (" "))) // and recombine. -; +require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', _ => + console . log (_ . trim () // Remove leading/trailing spaces + . split (/\s+/) // Split on white space + . reverse () // Reverse the words + . join (" "))) // And join them again. |
