diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2021-01-13 00:49:18 +0000 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2021-01-13 00:49:18 +0000 |
| commit | 0b4ca439c671315dd9f9bfae6e0f57f7469569f2 (patch) | |
| tree | 6271659fd956cf7b6a6db6d7fe23a557fbccac40 | |
| parent | ef60f41180fee0e36c1aa2ddd4f315738c2156f0 (diff) | |
| download | perlweeklychallenge-club-0b4ca439c671315dd9f9bfae6e0f57f7469569f2.tar.gz perlweeklychallenge-club-0b4ca439c671315dd9f9bfae6e0f57f7469569f2.tar.bz2 perlweeklychallenge-club-0b4ca439c671315dd9f9bfae6e0f57f7469569f2.zip | |
Add nunovieira220 js solution to challenge 095
| -rw-r--r-- | challenge-095/nunovieira220/js/ch-1.js | 9 | ||||
| -rw-r--r-- | challenge-095/nunovieira220/js/ch-2.js | 37 |
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-095/nunovieira220/js/ch-1.js b/challenge-095/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..9b1f3141e5 --- /dev/null +++ b/challenge-095/nunovieira220/js/ch-1.js @@ -0,0 +1,9 @@ +// Input +const num = 1221; + +// Palindrome Number +const numStr = `${num}`; +const res = numStr === numStr.split('').reverse().join('') ? 1 : 0; + +// Output +console.log(res);
\ No newline at end of file diff --git a/challenge-095/nunovieira220/js/ch-2.js b/challenge-095/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..cb08c08503 --- /dev/null +++ b/challenge-095/nunovieira220/js/ch-2.js @@ -0,0 +1,37 @@ +// Stack class +class Stack { + constructor() { + this.stack = []; + } + + push(elem) { + this.stack.push(elem); + } + + pop() { + return this.stack.pop(); + } + + top() { + return this.stack[this.stack.length - 1]; + } + + min() { + return Math.min(...this.stack); + } + + toString() { + console.log(this.stack); + } +} + +// Input +const stack = new Stack(); +stack.push(2); +stack.push(-1); +stack.push(0); +stack.pop(); // removes 0 +console.log(stack.top()); // prints -1 +stack.push(0); +console.log(stack.min()); // prints -1 +stack.toString();
\ No newline at end of file |
