Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame contribute delete
718 Bytes
import Big from "big.js";
export default function operate(numberOne, numberTwo, operation) {
const one = Big(numberOne || "0");
const two = Big(numberTwo || (operation === "÷" || operation === 'x' ? "1": "0")); //If dividing or multiplying, then 1 maintains current value in cases of null
if (operation === "+") {
return one.plus(two).toString();
}
if (operation === "-") {
return one.minus(two).toString();
}
if (operation === "x") {
return one.times(two).toString();
}
if (operation === "÷") {
if (two === "0") {
alert("Divide by 0 error");
return "0";
} else {
return one.div(two).toString();
}
}
throw Error(`Unknown operation '${operation}'`);
}