aboutsummaryrefslogtreecommitdiff
path: root/challenge-095/abigail/node/ch-1.js
blob: b753147ba95697c319e492a8914319ff12c56602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//
// Make a pattern matching an unsigned decimal number.
//
var XRegExp = require ('xregexp');
var pattern = XRegExp ('^\\p{Nd}+(?:\\.\\p{Nd}+)?$', 'u');

  require      ("fs")
. readFileSync (0)               // Read all.
. toString     ()                // Turn it into a string.
. split        ("\n")            // Split on newlines.
                                 // Remove trailing empty line.
. filter       ((_, i, a) => i != a . length - 1)
                                 // Check wether the input is a) a palindrome,
                                 // and 2) a decimal number.
                                 //
. map          (_ => console . log (_ == _ . split   ("")
                                           . reverse ()
                                           . join    ("") &&
                                    XRegExp . match (_, pattern) ? 1 : 0))
;