I am practicing my javascript
in CodeWars and I have come across this question:
Write a function that returns the
String
with the sum of two numbers. The parameters are two numbers but of typeString
.
Notes:
- The inputs are large.
- The inputs are
strings
containing only numbers. - The numbers are positive.
For what I did:
function add(a, b) {
return (Number(a) + Number(b))+"";
}
For small numbers there is no problem, I pass the tests well, but for large numbers it fails to change the notation.
Tests:
✔ Test Passed: Value == '100'
✔ Test Passed: Value == '8670'
✔ Test Passed: Value == '5'
✘ sumStrings('712569312664357328695151392', '8100824045303269669937') -
Expected: '712577413488402631964821329', instead got: '7.125774134884027e+26'
✘ sumStrings('50095301248058391139327916261', '81055900096023504197206408605') -
Expected: '131151201344081895336534324866', instead got: '1.3115120134408189e+29'
Probably a bullshit but I can not think of it. How can I solve this problem?