mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 22:28:10 +09:00
34 lines
486 B
JavaScript
34 lines
486 B
JavaScript
class Calculator {
|
|
add(a, b) {
|
|
return a + b;
|
|
}
|
|
|
|
subtract(a, b) {
|
|
return a - b;
|
|
}
|
|
|
|
multiply(a, b) {
|
|
return a * b;
|
|
}
|
|
|
|
divide(a, b) {
|
|
if (b === 0) {
|
|
throw new Error('Division by zero');
|
|
}
|
|
return a / b;
|
|
}
|
|
|
|
power(base, exponent) {
|
|
return Math.pow(base, exponent);
|
|
}
|
|
|
|
sqrt(n) {
|
|
if (n < 0) {
|
|
throw new Error('Cannot calculate square root of negative number');
|
|
}
|
|
return Math.sqrt(n);
|
|
}
|
|
}
|
|
|
|
module.exports = Calculator;
|