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 | |
| 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')
| -rw-r--r-- | challenge-110/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-110/abigail/node/ch-2.js | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md index c8b41d05d1..679024e8bb 100644 --- a/challenge-110/abigail/README.md +++ b/challenge-110/abigail/README.md @@ -80,6 +80,7 @@ sex,m,m,f,f * [Bash](bash/ch-2.ch) * [C](c/ch-2.c) * [Lua](lua/ch-2.lua) +* [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) ### Blog 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. |
