Sum String Integers
by Mark Allen
HTML
<script src="https://searls.github.io/jasmine-all/jasmine-all-min.js"></script>
JavaScript
// Given a variable amount of numbers as strings,
// return the string representation of the sum of those numbers.
//
// Use no external libraries.
//
// Example: sumStrings("1", "2", "3") // => "6"
var sumStrings = function (/* arguments */) {
// TODO
}
// TEST CASES:
var testCases = [
[["1", "2"], "3"],
[["3", "2", "1"], "6"],
[["0001", "002", "03"], "6"],
[["00103", "08567"], "8670"],
[["", "", "5"], "5"],
[
[
"712569312664357328695151392",
"8100824045303269669937"
],
"712577413488402631964821329"
],
[
[
"712569312664357328695151392",
"8100824045303269669937",
"5734659234572634583476529347823"
],
"5735371811986122986108494169152"
]
];
testCases.forEach(function (testCase) {
var input = testCase[0]
, expected = testCase[1];
describe("when input is " + input, function () {
it("returns " + expected, function () {
var actual = sumStrings.apply(undefined, input);
expect(actual).toEqual(expected);
});
});
});