This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity posts.
AI solution for JavaScript Coding Question on BFE.dev
126. BigDecimal addition
One possible solution using the Big.js library:
function add(a, b) { const Big = require('big.js'); const result = new Big(a).plus(b); return result.toString();}
First, we import the Big.js library. Then we create a new Big object with each input string, and use the plus()
method to add them together. Finally, we convert the result back to a string using the toString()
method and return it.
Note that Big.js automatically handles trailing zeroes in the result.