aboutsummaryrefslogtreecommitdiff
path: root/challenge-078
diff options
context:
space:
mode:
Diffstat (limited 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