aboutsummaryrefslogtreecommitdiff
path: root/challenge-252
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2024-02-18 00:52:20 -0500
committerDavid Ferrone <zapwai@gmail.com>2024-02-18 00:52:20 -0500
commit0bd71eed59c59babee8d119941376d86fb1caf4e (patch)
tree703519b50a4a5eb332ce0fe9c7e24550f20cfbf7 /challenge-252
parent2a77cc653444bfd4aaa507359f2b9f641e7cb920 (diff)
downloadperlweeklychallenge-club-0bd71eed59c59babee8d119941376d86fb1caf4e.tar.gz
perlweeklychallenge-club-0bd71eed59c59babee8d119941376d86fb1caf4e.tar.bz2
perlweeklychallenge-club-0bd71eed59c59babee8d119941376d86fb1caf4e.zip
PWC Forever
Diffstat (limited to 'challenge-252')
-rw-r--r--challenge-252/zapwai/javascript/ch-1.js25
-rw-r--r--challenge-252/zapwai/javascript/ch-2.js17
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-252/zapwai/javascript/ch-1.js b/challenge-252/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..8b95a0d51c
--- /dev/null
+++ b/challenge-252/zapwai/javascript/ch-1.js
@@ -0,0 +1,25 @@
+let ints = [1, 2, 3, 4];
+let ints2 = [2, 7, 1, 19, 18, 3];
+
+proc(ints);
+proc(ints2);
+
+function total( list ) {
+ let sum = 0;
+ for (let i of list) {
+ sum += i*i;
+ }
+ return sum;
+}
+
+function proc( ints ) {
+ let n = ints.length;
+ let spec = [];
+ for (let i = 0; i < n; i++) {
+ if (n % (i + 1) == 0) {
+ spec.push(ints[i]);
+ }
+ }
+ console.log("Input:", ints);
+ console.log("Output:", total( spec ));
+}
diff --git a/challenge-252/zapwai/javascript/ch-2.js b/challenge-252/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..1fe5b40823
--- /dev/null
+++ b/challenge-252/zapwai/javascript/ch-2.js
@@ -0,0 +1,17 @@
+let inputs = [5, 3, 1];
+for (let inp of inputs) {
+ proc(inp);
+}
+function proc(n) {
+ let list = [];
+ if (n % 2 == 1) {
+ list.push(0);
+ }
+ let k = parseInt(n / 2);
+ for (let i = 0; i < k; i++) {
+ list.push(-1 * (i+1));
+ list.push(i+1);
+ }
+ console.log("Input:", n);
+ console.log("Output:", list);
+}