aboutsummaryrefslogtreecommitdiff
path: root/challenge-135/abigail/node/ch-1.js
blob: a16d936f9d207fdf1fc2b36a946354f3d80a8c87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/local/bin/node

//
// See ../README.md
//

//
// Run as: node ch-1.js < input-file
//

  require ('readline')
. createInterface ({input: process . stdin})   
. on              ('line', line => {
    line = line . replace (/^[-+]/, '') . trim ()
    if (line . match (/[^0-9]/)) {
        console . log ("not an integer")
    }
    else {
        if (line . length % 2 == 0) {
            console . log ("even number of digits")
        }
        else {
            if (line . length < 3) {
                console . log ("too short")
            }
            else {
                console . log (line . substr ((line . length - 3) / 2, 3))
            }
        }
    }
})