aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Vieira <nunovieira220@gmail.com>2020-09-16 00:56:22 +0100
committerNuno Vieira <nunovieira220@gmail.com>2020-09-16 00:56:22 +0100
commitc983520f6b94ea29c6b0dba61ed36e2a6765b5ea (patch)
tree16d59e9bfafbedb491af4e318d3e7f4608ed84df
parent3a4cbc746cb3fe57a98dc2c6ad519483f3f9044e (diff)
downloadperlweeklychallenge-club-c983520f6b94ea29c6b0dba61ed36e2a6765b5ea.tar.gz
perlweeklychallenge-club-c983520f6b94ea29c6b0dba61ed36e2a6765b5ea.tar.bz2
perlweeklychallenge-club-c983520f6b94ea29c6b0dba61ed36e2a6765b5ea.zip
Add nunovieira220 js solution to challenge 078
-rw-r--r--challenge-078/nunovieira220/js/ch-1.js13
-rw-r--r--challenge-078/nunovieira220/js/ch-2.js21
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-078/nunovieira220/js/ch-1.js b/challenge-078/nunovieira220/js/ch-1.js
new file mode 100644
index 0000000000..0b2cb7cf38
--- /dev/null
+++ b/challenge-078/nunovieira220/js/ch-1.js
@@ -0,0 +1,13 @@
+
+// Input
+const list = [9, 10, 7, 5, 6, 1];
+
+// Get leader elements
+let arr = [];
+list.forEach(item => {
+ arr = arr.filter(elem => elem > item);
+ arr.push(item);
+});
+
+// Output
+console.log(arr.join(', ')); \ No newline at end of file
diff --git a/challenge-078/nunovieira220/js/ch-2.js b/challenge-078/nunovieira220/js/ch-2.js
new file mode 100644
index 0000000000..a923991cc6
--- /dev/null
+++ b/challenge-078/nunovieira220/js/ch-2.js
@@ -0,0 +1,21 @@
+// Input
+const A = [7, 4, 2, 6, 3];
+const B = [1, 3, 4];
+
+// Execute left rotation
+const arr = [];
+let index = 0;
+
+B.forEach(i => {
+ const jump = i - index;
+
+ for(let j = 0; j < jump; j++) {
+ const val = A.shift();
+ A.push(val);
+ }
+
+ index += jump;
+
+ // Output
+ console.log(A.join(', '));
+}); \ No newline at end of file