From c5ddab618e42c74be87e07c12026e797734804ab Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 17 Dec 2020 02:54:35 +0100 Subject: Node.js solution for week 091/part 2 --- challenge-091/abigail/node/ch-2.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-091/abigail/node/ch-2.js (limited to 'challenge-091') 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"); +} -- cgit