aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-111/stuart-little/node/ch-1.js28
-rwxr-xr-xchallenge-111/stuart-little/node/ch-2.js21
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);