diff options
| author | Abigail <abigail@abigail.be> | 2021-04-29 20:22:21 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-04-29 20:22:21 +0200 |
| commit | 953655fd36dd86735774f02b092e205b2f905d9f (patch) | |
| tree | 21b415fb7969002d7051257cc55e85897f79552c /challenge-110/abigail/node | |
| parent | 82a963ae8e975ee5aeaba94cf790c9966c437174 (diff) | |
| download | perlweeklychallenge-club-953655fd36dd86735774f02b092e205b2f905d9f.tar.gz perlweeklychallenge-club-953655fd36dd86735774f02b092e205b2f905d9f.tar.bz2 perlweeklychallenge-club-953655fd36dd86735774f02b092e205b2f905d9f.zip | |
Node.js solution for week 110, part 2
Diffstat (limited to 'challenge-110/abigail/node')
| -rw-r--r-- | challenge-110/abigail/node/ch-2.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-110/abigail/node/ch-2.js b/challenge-110/abigail/node/ch-2.js new file mode 100644 index 0000000000..6f41fcd92f --- /dev/null +++ b/challenge-110/abigail/node/ch-2.js @@ -0,0 +1,29 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-2.js < input-file +// + +let out = [] + + require ("fs") +. readFileSync (0) // Read all. +. toString () // Turn it into a string. +. split ("\n") // Split on newlines. +. filter (_ => _ . length) // Filter out empty lines. +. map (_ => _ . split (',')) // Split each line on commas +. forEach (_ => _ . + forEach ((field, index) => { // Create output strings + if (out [index] == null) { + out [index] = "" + } + out [index] += "," + field + })) + +out . forEach (_ => console . log (_ . substr (1))) // Print the output + // strings, skipping the + // leading comma. |
