diff options
| -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+/)))) ; // |
