aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-135/abigail/README.md2
-rw-r--r--challenge-135/abigail/node/ch-1.js32
-rw-r--r--challenge-135/abigail/node/ch-2.js29
3 files changed, 63 insertions, 0 deletions
diff --git a/challenge-135/abigail/README.md b/challenge-135/abigail/README.md
index 5d1820d670..9affa5c624 100644
--- a/challenge-135/abigail/README.md
+++ b/challenge-135/abigail/README.md
@@ -5,6 +5,7 @@
* [AWK](awk/ch-1.awk)
* [Bash](bash/ch-1.sh)
* [C](c/ch-1.c)
+* [Node.js](node/ch-1.js)
* [Perl](perl/ch-1.pl)
## Part 2
@@ -12,4 +13,5 @@
* [AWK](awk/ch-2.awk)
* [Bash](bash/ch-1.sh)
* [C](c/ch-2.c)
+* [Node.js](node/ch-1.js)
* [Perl](perl/ch-2.pl)
diff --git a/challenge-135/abigail/node/ch-1.js b/challenge-135/abigail/node/ch-1.js
new file mode 100644
index 0000000000..a16d936f9d
--- /dev/null
+++ b/challenge-135/abigail/node/ch-1.js
@@ -0,0 +1,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))
+ }
+ }
+ }
+})
+
diff --git a/challenge-135/abigail/node/ch-2.js b/challenge-135/abigail/node/ch-2.js
new file mode 100644
index 0000000000..d1ef83492a
--- /dev/null
+++ b/challenge-135/abigail/node/ch-2.js
@@ -0,0 +1,29 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-2.js < input-file
+//
+
+let w = [1, 3, 1, 7, 3, 9, 1]
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => {
+ line = line . trim ()
+ if (line . length != 7 || line . match (/[^0-9BCDFGHJKLMNPQRSTVWXYZ]/)) {
+ console . log (0)
+ }
+ else {
+ let check = 0
+ for (let i = 0; i < 7; i ++) {
+ let value = line . charCodeAt (i)
+ value -= value <= 57 ? 48 : 55
+ check += w [i] * value
+ }
+ console . log (check % 10 == 0 ? 1 : 0)
+ }
+})