diff --git a/tests/Q2/objectSum.js b/tests/Q2/objectSum.js index 4858fa8..7fed396 100644 --- a/tests/Q2/objectSum.js +++ b/tests/Q2/objectSum.js @@ -1,6 +1,13 @@ function objectSum(obj) { sum = 0 for (let number of obj){ + // Attempted to support objects + //if (typeof(number[1]) === "number") + // sum = sum + number[1] + //if (typeof(number[1]) === "object") + // sum = sum + objectSum(number[1]) + + //Case for when the number is actually not a number (eg, recursive list) if (typeof(number) === "object") sum = sum + objectSum(number) diff --git a/tests/Q2/spec/objectSum.spec.js b/tests/Q2/spec/objectSum.spec.js index f195ade..86f6e5e 100644 --- a/tests/Q2/spec/objectSum.spec.js +++ b/tests/Q2/spec/objectSum.spec.js @@ -16,5 +16,15 @@ function() { let obj = [1, 2, [-6, 2, -2], 3] expect(sum.objectSum(obj)).toBe(0); - }); + }); + it("Lists", + function() { + let obj = {a: 1, b: 2, c: 3} + expect(sum.objectSum(obj)).toBe(6); + }); + it("Recursive lists", + function() { + let obj = [1, 2, {thing: [-6, -12], other: 6}] + expect(sum.objectSum(obj)).toBe(-9); + }); });