diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2020-09-29 20:33:19 +0100 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2020-09-29 20:33:19 +0100 |
| commit | 99fc28fb74792d2f7d455c39b50e72041b1cb04d (patch) | |
| tree | 65795593ff1c8296d4d34021509fc1c1e10dbef9 | |
| parent | b295e8752d2d6a242ed88274a44a125e722683ce (diff) | |
| download | perlweeklychallenge-club-99fc28fb74792d2f7d455c39b50e72041b1cb04d.tar.gz perlweeklychallenge-club-99fc28fb74792d2f7d455c39b50e72041b1cb04d.tar.bz2 perlweeklychallenge-club-99fc28fb74792d2f7d455c39b50e72041b1cb04d.zip | |
Add nunovieira220 js solution to challenge 080
| -rw-r--r-- | challenge-080/nunovieira220/js/ch-1.js | 11 | ||||
| -rw-r--r-- | challenge-080/nunovieira220/js/ch-2.js | 13 |
2 files changed, 24 insertions, 0 deletions
diff --git a/challenge-080/nunovieira220/js/ch-1.js b/challenge-080/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..0f9036178c --- /dev/null +++ b/challenge-080/nunovieira220/js/ch-1.js @@ -0,0 +1,11 @@ +// Input +const A = [5, 2, -2, 0]; + +// Smallest positive number bits +const flags = [1]; + +A.forEach(n => { + if(n >= 0) flags[n] = 1; +}); + +console.log(flags.findIndex(Object.is.bind(null, undefined)));
\ No newline at end of file diff --git a/challenge-080/nunovieira220/js/ch-2.js b/challenge-080/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..d942aac84d --- /dev/null +++ b/challenge-080/nunovieira220/js/ch-2.js @@ -0,0 +1,13 @@ +// Input +const A = [1, 4, 3, 2]; + +// Count candies +let counter = A.length; + +A.push(Number.MAX_SAFE_INTEGER); + +for (let i = A.length - 1; i >= 0; i--) { + counter += (A[i] > A[i-1]) + (A[i] > A[i+1]); +} + +console.log(counter);
\ No newline at end of file |
