diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-04-26 09:43:31 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-04-26 09:43:31 -0400 |
| commit | 4d1d5bcbdda384852713056b7ad3e5c4c146297a (patch) | |
| tree | 072e85302c9c0656cea795f165a6c6f9e73fe021 | |
| parent | 1ff197d81f941c3dd35d77bec8a0326807e8d2b1 (diff) | |
| download | perlweeklychallenge-club-4d1d5bcbdda384852713056b7ad3e5c4c146297a.tar.gz perlweeklychallenge-club-4d1d5bcbdda384852713056b7ad3e5c4c146297a.tar.bz2 perlweeklychallenge-club-4d1d5bcbdda384852713056b7ad3e5c4c146297a.zip | |
1st commit on 110_node
| -rwxr-xr-x | challenge-110/stuart-little/node/ch-1.js | 23 | ||||
| -rwxr-xr-x | challenge-110/stuart-little/node/ch-2.js | 23 |
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(",")) +); |
