aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-091/abigail/node/ch-2.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-091/abigail/node/ch-2.js b/challenge-091/abigail/node/ch-2.js
new file mode 100644
index 0000000000..5c65b9763a
--- /dev/null
+++ b/challenge-091/abigail/node/ch-2.js
@@ -0,0 +1,22 @@
+//
+// Read STDIN. Split on newlines, filter out empty lines,
+// split each line on white space, then call "show"
+//
+ 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 (/\s+/) // Split on whitespace.
+ . map (_ => +_)) // And numify the parts.
+. map (_ => hop (_))
+;
+
+//
+// Do the main work
+//
+function hop (array) {
+ let i;
+ for (i = 0; i < array . length - 1; i += array [i]) {}
+ process . stdout . write (i == (array . length - 1) ? "1\n" : "0\n");
+}