aboutsummaryrefslogtreecommitdiff
path: root/challenge-146/abigail/node/ch-2.js
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-146/abigail/node/ch-2.js')
-rw-r--r--challenge-146/abigail/node/ch-2.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-146/abigail/node/ch-2.js b/challenge-146/abigail/node/ch-2.js
new file mode 100644
index 0000000000..ce7fba74c7
--- /dev/null
+++ b/challenge-146/abigail/node/ch-2.js
@@ -0,0 +1,31 @@
+#!/usr/local/bin/node
+
+//
+// See ../README.md
+//
+
+//
+// Run as: node ch-2.js < input-file
+//
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => {
+ let [a, b] = line . trim () . split ("/") . map (x => +x)
+ for (let i = 1; i <= 2; i ++) {
+ if (a < b) {
+ b -= a
+ }
+ else {
+ a -= b
+ }
+ if (a == 0 || b == 0) {
+ break
+ }
+ process . stdout . write (a . toString ())
+ process . stdout . write ("/")
+ process . stdout . write (b . toString ())
+ process . stdout . write (" ")
+ }
+ process . stdout . write ("\n")
+})