From c983520f6b94ea29c6b0dba61ed36e2a6765b5ea Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Wed, 16 Sep 2020 00:56:22 +0100 Subject: Add nunovieira220 js solution to challenge 078 --- challenge-078/nunovieira220/js/ch-1.js | 13 +++++++++++++ challenge-078/nunovieira220/js/ch-2.js | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 challenge-078/nunovieira220/js/ch-1.js create mode 100644 challenge-078/nunovieira220/js/ch-2.js 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 -- cgit