Create a simple String calculator function, that takes two numbers and returns their sum.
The input is a string, the method can take up to two numbers, separated by commas, and will return their sum as a number.
For an empty string: ""
, it will return 0
Examples:
"1,2"
should return 3
"42"
should return 42
.""
should return 0
.In the editor below, you can implement it in JavaScript, and Mocha and Chai unit test librairies are preset.
Try not to read ahead until you have completed the first step
Do one task at a time. The trick is to learn to work incrementally.
Make sure you only test for correct inputs.
There is no need to test for invalid inputs for this kata
Allow the calculateSum()
function to handle an unknown amount of numbers
Allow the calculateSum()
function to handle the symbol @
between numbers (in addition of commas).
Examples:
"1@2,3"
should return 6
"2@2@6"
should return 10
."2,3,4@3,2"
should return 14
.