aboutsummaryrefslogtreecommitdiff
path: root/challenge-289/zapwai/javascript/ch-2.js
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-30 22:00:03 +0100
committerGitHub <noreply@github.com>2024-09-30 22:00:03 +0100
commit4fc5b1d10239d98f05d83c95f22ec6becd111cd5 (patch)
treeec444747cd7c8c4cb47cd11cd248e980eff6b805 /challenge-289/zapwai/javascript/ch-2.js
parente4cdda8a1053c2bcd7d33bbad494158355fd0b3c (diff)
parentef99aabc641bef7ebe24b809e401babda7dfc5fe (diff)
downloadperlweeklychallenge-club-4fc5b1d10239d98f05d83c95f22ec6becd111cd5.tar.gz
perlweeklychallenge-club-4fc5b1d10239d98f05d83c95f22ec6becd111cd5.tar.bz2
perlweeklychallenge-club-4fc5b1d10239d98f05d83c95f22ec6becd111cd5.zip
Merge pull request #10935 from zapwai/branch-for-289
Week 289
Diffstat (limited to 'challenge-289/zapwai/javascript/ch-2.js')
-rw-r--r--challenge-289/zapwai/javascript/ch-2.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-289/zapwai/javascript/ch-2.js b/challenge-289/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..c6e50f31ca
--- /dev/null
+++ b/challenge-289/zapwai/javascript/ch-2.js
@@ -0,0 +1,33 @@
+let s = "This supposed Cambridge research is unfortunately an urban legend";
+proc(s);
+
+function jumble(word) {
+ if (word.length < 4) {
+ return word;
+ }
+ let Let = word.split("");
+ let start = Let[0];
+ let end = Let[Let.length - 1];
+ Let.pop();
+ Let.shift();
+ let order = [];
+ while (order.length < Let.length) {
+ let x = Math.floor(Math.random() * Let.length);
+ if (!order.includes(x)) {
+ order.push(x);
+ }
+ }
+ let middle = "";
+ for (let o of order) {
+ middle += Let[o];
+ }
+ let q = start + middle + end;
+ return q;
+}
+
+function proc(s) {
+ console.log( "Input:", s);
+ let words = s.split(" ");
+ let newlist = (words.map(x => jumble(x)));
+ console.log( "Output:", newlist.join(' ') );
+}