diff options
| author | David Ferrone <zapwai@gmail.com> | 2024-09-16 12:02:14 -0400 |
|---|---|---|
| committer | David Ferrone <zapwai@gmail.com> | 2024-09-16 12:02:14 -0400 |
| commit | 3e3e9530a265cb3f549a3556bb78ffdcb1023650 (patch) | |
| tree | 0ff6a6be7fb3e633fa486069899c8df2df046785 /challenge-287/zapwai/javascript | |
| parent | eae3cd347219654833096d39e152c603f15e7292 (diff) | |
| download | perlweeklychallenge-club-3e3e9530a265cb3f549a3556bb78ffdcb1023650.tar.gz perlweeklychallenge-club-3e3e9530a265cb3f549a3556bb78ffdcb1023650.tar.bz2 perlweeklychallenge-club-3e3e9530a265cb3f549a3556bb78ffdcb1023650.zip | |
Week 287
Diffstat (limited to 'challenge-287/zapwai/javascript')
| -rw-r--r-- | challenge-287/zapwai/javascript/ch-1.js | 63 | ||||
| -rw-r--r-- | challenge-287/zapwai/javascript/ch-2.js | 39 |
2 files changed, 102 insertions, 0 deletions
diff --git a/challenge-287/zapwai/javascript/ch-1.js b/challenge-287/zapwai/javascript/ch-1.js new file mode 100644 index 0000000000..716ad43bb9 --- /dev/null +++ b/challenge-287/zapwai/javascript/ch-1.js @@ -0,0 +1,63 @@ +let str = "a"; +proc(str); +str = "aB2"; +proc(str); +str = "PaaSW0rd"; +proc(str); +str = "turbbbbot"; +proc(str); +str = "111"; +proc(str); + +function proc(str) { + console.log( "Input:", str); + let len = str.length; + let len_diff = 0; + if (len < 6) { + len_diff = 6 - len; + } else if (len > 20) { + len_diff = len - 20; + } + let l = str.split(""); + let lengths = []; + let hits = 0; + for (let i = 0; i < l.length - 1; i++) { + if (l[i] == l[i+1]) { + hits++; + } else { + if (hits > 1) { + lengths.push(1+hits); + } + hits = 0; + } + } + if (hits > 1) { + lengths.push(1+hits); + } + let steps = 0; + for (let l of lengths) { + steps += Math.floor(l/3); + } + let lflag = 1; + let uflag = 1; + let dflag = 1; + let lreg = new RegExp('[a-z]'); + let ureg = new RegExp('[A-Z]'); + let dreg = new RegExp('\d'); + if (lreg.test(str)) { + lflag = 0; + } + if (ureg.test(str)) { + uflag = 0; + } + if (dreg.test(str)) { + dflag = 0; + } + let tally = lflag + uflag + dflag; + let out_val = len_diff + steps; + if (out_val < tally) { + out_val += tally - out_val; + } + console.log( "Output: ", out_val); +} + diff --git a/challenge-287/zapwai/javascript/ch-2.js b/challenge-287/zapwai/javascript/ch-2.js new file mode 100644 index 0000000000..23e068bc82 --- /dev/null +++ b/challenge-287/zapwai/javascript/ch-2.js @@ -0,0 +1,39 @@ +let str = "1"; +proc(str); +str = "56e10"; +proc(str); +str = "2E32"; +proc(str); +str = "a"; +proc(str); +str = "1.2"; +proc(str); +str = "1.2.6"; +proc(str); +str = "3.142e10"; +proc(str); +str = "3.142e42B"; +proc(str); + +function proc(str) { + console.log( "Input:", str); + let output = "False"; + let p = str.split("."); + let dre = /^\d+$/ + let dere = /^\d+e\d+$|^\d+E\d+$/; + let deere = /^\d+e\d+$|^\d+E\d+$/; + if (p.length == 1) { + if (dre.test(str)) { + output = "True"; + } else if (dere.test(str)) { + output = "True"; + } + } else if (p.length == 2) { + if (dre.test(p[0]) && dre.test(p[1])) { + output = "True"; + } else if (dre.test(p[0]) && deere.test(p[1])) { + output = "True"; + } + } + console.log("Output:", output); +} |
