diff options
Diffstat (limited to 'challenge-274/zapwai/javascript')
| -rw-r--r-- | challenge-274/zapwai/javascript/ch-1.js | 32 | ||||
| -rw-r--r-- | challenge-274/zapwai/javascript/ch-2.js | 24 |
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-274/zapwai/javascript/ch-1.js b/challenge-274/zapwai/javascript/ch-1.js new file mode 100644 index 0000000000..6d39695393 --- /dev/null +++ b/challenge-274/zapwai/javascript/ch-1.js @@ -0,0 +1,32 @@ +let sent = "I love Perl"; +proc(sent); +sent = "Perl and Raku are friends"; +proc(sent); +sent = "The Weekly Challenge"; +proc(sent); + +function isVowel(c) { + let d = c.toLowerCase() + return (d == 'a' || d == 'e' || d == 'i' || d == 'o' || d == 'u') +} + +function proc(sent) { + console.log("Input:", sent); + let words = sent.split(" "); + for (let i = 0; i < words.length; i++) { + let A = ""; + for (let j = 0; j < i; j++) { + A += "a"; + } + let lets = words[i].split(""); + let first_let = lets[0]; + lets.shift(); + let reword = lets.join(''); + reword += first_let; + if (isVowel(first_let)) { + console.log("Output", words[i]+"ma"+A+" "); + } else { + console.log("Output", reword+"ma"+A+" "); + } + } +} diff --git a/challenge-274/zapwai/javascript/ch-2.js b/challenge-274/zapwai/javascript/ch-2.js new file mode 100644 index 0000000000..30c1c76dd2 --- /dev/null +++ b/challenge-274/zapwai/javascript/ch-2.js @@ -0,0 +1,24 @@ +let r1 = [11, 23, 35, 47, 59]; +let r2 = [5, 20, 35, 50, 65]; +let length_one = 41; +let length_two = 35; +let out = ""; +for (let t = 1; t < 59; t++) { + let delta_one = delta(t, r1); + let delta_two = delta(t, r2); + let time_taken_one = length_one + delta_one; + let time_taken_two = length_two + delta_two; + if ((delta_one <= delta_two) && (time_taken_one > time_taken_two)) { + out += t+" "; + } +} +console.log(out); + +function delta(t, ran) { + for (let r of ran) { + if (r < t) { + continue; + } + return r - t; + } +} |
