-
Notifications
You must be signed in to change notification settings - Fork 0
/
day-17-more-exceptions.js
46 lines (42 loc) · 1.01 KB
/
day-17-more-exceptions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* eslint-disable no-throw-literal */
process.stdin.resume();
process.stdin.setEncoding('ascii');
let input_stdin = '';
let input_stdin_array = '';
let input_currentline = 0;
process.stdin.on('data', (data) => {
input_stdin = input_stdin + data;
});
process.stdin.on('end', () => {
input_stdin_array = input_stdin.split('\n');
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
// Write your code here
class Calculator {
power(int, exp) {
// https://eslint.org/docs/rules/no-throw-literal
// eslint-disable-next-line no-throw-literal
if (int < 0 || exp < 0) {
throw 'n and p should be non-negative';
}
return int ** exp;
}
}
function main() {
let myCalculator = new Calculator();
let T = parseInt(readLine());
while (T-- > 0) {
let num = readLine().split(' ');
try {
let n = parseInt(num[0]);
let p = parseInt(num[1]);
let ans = myCalculator.power(n, p);
console.log(ans);
} catch (e) {
console.log(e);
}
}
}