implement BigInt subtraction
2022年5月1日小于 1 分钟
implement BigInt subtraction
Question
Luckily we already have built-in support of BigInt in JavaScript, at least in some browsers.
1000000000000000000000n - 999999999999999999999n
// 1n
Suppose BigInt cannot be used, can you implement a string subtraction function by yourself?
subtract('1000000000000000000000', '999999999999999999999')
// '1'
All input are valid non-negative integer strings, and the result is guaranteed to be non-negative.
Don't use BigInt directly, it is not our goal here
Code
/**
* @param {string} num1
* @param {string} num2
* @return {string}
*/
function subtract(num1, num2) {
// your code here
}