aboutsummaryrefslogtreecommitdiff
path: root/challenge-091/abigail/node/ch-2.js
blob: 5c65b9763aca03c52389cf17f5958c1f69eecf8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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");
}