aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-110/stuart-little/node/ch-1.js23
-rwxr-xr-xchallenge-110/stuart-little/node/ch-2.js23
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-110/stuart-little/node/ch-1.js b/challenge-110/stuart-little/node/ch-1.js
new file mode 100755
index 0000000000..2627e204e5
--- /dev/null
+++ b/challenge-110/stuart-little/node/ch-1.js
@@ -0,0 +1,23 @@
+#!/usr/bin/env node
+
+// run <script> <path-to-file or nothing>
+// defaults to challenge sample if no file is entered
+
+const fs = require('fs');
+
+const data = (process.argv.length<=2) ? (`0044 1148820341
+ +44 1148820341
+ 44-11-4882-0341
+(44) 1148820341
+ 00 1148820341
+`) : fs.readFileSync(process.argv[2], 'utf8', function (err,data) {
+ if (err) {
+ return console.log(err);
+ }
+ return data;
+});
+
+let rgx = new RegExp(/((?:\+\d{2}|\(\d{2}\)|\d{4})\s+\d{10})/,'g');
+for (nr of [...data.matchAll(rgx)].map(x => x[0])) {
+ console.log(nr);
+};
diff --git a/challenge-110/stuart-little/node/ch-2.js b/challenge-110/stuart-little/node/ch-2.js
new file mode 100755
index 0000000000..bd8c0c0ab1
--- /dev/null
+++ b/challenge-110/stuart-little/node/ch-2.js
@@ -0,0 +1,23 @@
+#!/usr/bin/env node
+
+// run <script> <path-to-file or nothing>
+// defaults to challenge sample if no file is entered
+
+const fs = require('fs');
+const _ = require('lodash');
+
+const data = (process.argv.length<=2) ? (`name,age,sex
+Mohammad,45,m
+Joe,20,m
+Julie,35,f
+Cristina,10,f
+`) : fs.readFileSync(process.argv[2], 'utf8', function (err,data) {
+ if (err) {
+ return console.log(err);
+ }
+ return data;
+});
+
+console.log(
+ _.zip(...data.trim().split("\n").map(x => x.split(","))).map(x => x.join(","))
+);