aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/abigail/node
diff options
context:
space:
mode:
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.