aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/abigail/node
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-04-29 20:22:21 +0200
committerAbigail <abigail@abigail.be>2021-04-29 20:22:21 +0200
commit953655fd36dd86735774f02b092e205b2f905d9f (patch)
tree21b415fb7969002d7051257cc55e85897f79552c /challenge-110/abigail/node
parent82a963ae8e975ee5aeaba94cf790c9966c437174 (diff)
downloadperlweeklychallenge-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.js29
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.