diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-05-03 19:19:20 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-05-03 19:19:20 -0400 |
| commit | f4f176418dbd531ea2c866a5c733a1f4332ef9b1 (patch) | |
| tree | 58f7666dcd6516fb37b10285c2c4c9d5a65429ac | |
| parent | 22e2dadf4982b862c3cf0679b40d76d2b8f9daf8 (diff) | |
| download | perlweeklychallenge-club-f4f176418dbd531ea2c866a5c733a1f4332ef9b1.tar.gz perlweeklychallenge-club-f4f176418dbd531ea2c866a5c733a1f4332ef9b1.tar.bz2 perlweeklychallenge-club-f4f176418dbd531ea2c866a5c733a1f4332ef9b1.zip | |
1st commit on 111_node
| -rwxr-xr-x | challenge-111/stuart-little/node/ch-1.js | 28 | ||||
| -rwxr-xr-x | challenge-111/stuart-little/node/ch-2.js | 21 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-111/stuart-little/node/ch-1.js b/challenge-111/stuart-little/node/ch-1.js new file mode 100755 index 0000000000..5969df50c5 --- /dev/null +++ b/challenge-111/stuart-little/node/ch-1.js @@ -0,0 +1,28 @@ +#!/usr/bin/env node + +// run <script> + +const _ = require('lodash'); + +function binFindZero1(needle,mat) { + return (_.sortedIndexOf(_.flatten(mat),needle) >= 0) ? (1) : (0); +} + +const inArr = [ + [ 1, 2, 3, 5, 7 ], + [ 9, 11, 15, 19, 20 ], + [ 23, 24, 25, 29, 31 ], + [ 32, 33, 39, 40, 42 ], + [ 45, 47, 48, 49, 50 ], +]; + +const toSearch = [1,35,39,100]; + +console.log("Array:"); +inArr.forEach(row => console.log(row)); + +toSearch.forEach( + needle => { + console.log(`\nFound ${needle}?`); + console.log(binFindZero1(needle,inArr)); + }); diff --git a/challenge-111/stuart-little/node/ch-2.js b/challenge-111/stuart-little/node/ch-2.js new file mode 100755 index 0000000000..c2cf336c2d --- /dev/null +++ b/challenge-111/stuart-little/node/ch-2.js @@ -0,0 +1,21 @@ +#!/usr/bin/env node + +// run <script> <path-to-dict-file, one word per line> + +const _ = require('lodash'); +const fs = require('fs'); + +function isSorted(arr) { + return arr.every((el,ix,ar) => {return ix == ar.length-1 || ar[ix] <= ar[ix+1]}) +} + +const wrds = fs.readFileSync(process.argv[2]).toString().split("\n"); + +const res = _.maxBy( + Object.entries( + _.groupBy(wrds.filter(wrd => { + return isSorted(wrd.toLowerCase().split('')) + }), 'length') + ), (entry) => parseInt(entry)); + +console.log(res); |
