aboutsummaryrefslogtreecommitdiff
path: root/challenge-078
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-16 02:12:39 +0100
committerGitHub <noreply@github.com>2020-09-16 02:12:39 +0100
commitd82a7d3c8e5bdfcc4bb3ad2f0d943fb445d8a33e (patch)
treec969050a72e612e7a1ae5c87b59a4ead9954bc34 /challenge-078
parentb7c69245e0ad553494a646a2ea9b93f8f8ccd35d (diff)
parentc983520f6b94ea29c6b0dba61ed36e2a6765b5ea (diff)
downloadperlweeklychallenge-club-d82a7d3c8e5bdfcc4bb3ad2f0d943fb445d8a33e.tar.gz
perlweeklychallenge-club-d82a7d3c8e5bdfcc4bb3ad2f0d943fb445d8a33e.tar.bz2
perlweeklychallenge-club-d82a7d3c8e5bdfcc4bb3ad2f0d943fb445d8a33e.zip
Merge pull request #2305 from nunovieira220/challenge-078
Add solution to challenge 078
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
-rw-r--r--challenge-078/nunovieira220/perl/ch-1.pl18
-rw-r--r--challenge-078/nunovieira220/perl/ch-2.pl27
4 files changed, 79 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
diff --git a/challenge-078/nunovieira220/perl/ch-1.pl b/challenge-078/nunovieira220/perl/ch-1.pl
new file mode 100644
index 0000000000..3cd1fa33f2
--- /dev/null
+++ b/challenge-078/nunovieira220/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Input
+my @list = scalar @ARGV ? @ARGV : (9, 10, 7, 5, 6, 1);
+
+# Get leader elements
+my @arr = ();
+for my $item (@list) {
+ @arr = grep { $_ > $item } @arr;
+ push @arr, $item;
+}
+
+# Output
+my $res = join ", ", @arr;
+print $res."\n"; \ No newline at end of file
diff --git a/challenge-078/nunovieira220/perl/ch-2.pl b/challenge-078/nunovieira220/perl/ch-2.pl
new file mode 100644
index 0000000000..80d345396b
--- /dev/null
+++ b/challenge-078/nunovieira220/perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Input
+my @A = (7, 4, 2, 6, 3);
+my @B = (1, 3, 4);
+
+# Execute left rotation
+my @arr = ();
+my $index = 0;
+
+for my $i (@B) {
+ my $jump = $i - $index;
+
+ for(my $j = 0; $j < $jump; $j++) {
+ my $val = shift @A;
+ push @A, $val;
+ }
+
+ $index += $jump;
+
+ # Output
+ my $res = join ", ", @A;
+ print $res."\n";
+} \ No newline at end of file