diff options
| -rw-r--r-- | challenge-079/nunovieira220/js/ch-1.js | 12 | ||||
| -rw-r--r-- | challenge-079/nunovieira220/js/ch-2.js | 17 |
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-079/nunovieira220/js/ch-1.js b/challenge-079/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..9216296d84 --- /dev/null +++ b/challenge-079/nunovieira220/js/ch-1.js @@ -0,0 +1,12 @@ +// Input +const N = 4; + +// Count set bits +let counter = 0; + +Array.from({ length: N }, (_, i) => i + 1).forEach(n => { + const bin = parseInt(n, 10).toString(2); + counter += bin.split('1').length - 1; +}); + +console.log(counter);
\ No newline at end of file diff --git a/challenge-079/nunovieira220/js/ch-2.js b/challenge-079/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..6fe1744ee6 --- /dev/null +++ b/challenge-079/nunovieira220/js/ch-2.js @@ -0,0 +1,17 @@ +// Input +const A = [3, 1, 3, 1, 1, 5]; + +// Trapped rain water counter +let counter = 0; +let max = 0; + +A.forEach(item => { + if(item >= max) { + max = item; + } else { + counter += max - item; + } +}); + +// Output +console.log(counter);
\ No newline at end of file |
