diff options
| author | Abigail <abigail@abigail.be> | 2021-01-23 22:02:02 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-23 22:02:02 +0100 |
| commit | 0f5c21ad90c5f91fe51b3f053edac74e420ff536 (patch) | |
| tree | 7ec72cc5b1e340aa982e7277608c104856fc8afc /challenge-096/abigail/node | |
| parent | 6172b5279612e72e5480ecc2ca6f13fa55d2cf8f (diff) | |
| download | perlweeklychallenge-club-0f5c21ad90c5f91fe51b3f053edac74e420ff536.tar.gz perlweeklychallenge-club-0f5c21ad90c5f91fe51b3f053edac74e420ff536.tar.bz2 perlweeklychallenge-club-0f5c21ad90c5f91fe51b3f053edac74e420ff536.zip | |
Use the 'readline' module to iterate over the input.
Diffstat (limited to 'challenge-096/abigail/node')
| -rw-r--r-- | challenge-096/abigail/node/ch-1.js | 30 | ||||
| -rw-r--r-- | challenge-096/abigail/node/ch-2.js | 20 |
2 files changed, 29 insertions, 21 deletions
diff --git a/challenge-096/abigail/node/ch-1.js b/challenge-096/abigail/node/ch-1.js index b31524a686..cbc7e56d60 100644 --- a/challenge-096/abigail/node/ch-1.js +++ b/challenge-096/abigail/node/ch-1.js @@ -1,15 +1,19 @@ +#!/usr/local/bin/node + // -// Read STDIN. Split on newlines, filter out empty lines, then call "main". -// - 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. +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + +require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', _ => console . log (_ . trim () // Remove leading + // and trailing + // whitespace. + . split (/\s+/) // split ... + . reverse () // reverse ... + . join (" "))) // and recombine. ; diff --git a/challenge-096/abigail/node/ch-2.js b/challenge-096/abigail/node/ch-2.js index 8423ab96b8..59079c4cad 100644 --- a/challenge-096/abigail/node/ch-2.js +++ b/challenge-096/abigail/node/ch-2.js @@ -1,13 +1,17 @@ +#!/usr/local/bin/node + +// +// See ../README.md // -// Read STDIN. Split on newlines, filter out empty lines, then call "main". + // - 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 (LevenshteinDistance (_ . trim () - . split (/\s+/)))) +// Run as: node ch-2.js < input-file +// + +require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', _ => console . log (LevenshteinDistance (_ . trim () + . split (/\s+/)))) ; // |
