"use strict"; function addArr(arr) { return arr.length === 0 ? null : arr.reduce((acc, x) => acc + x, 0); }
function addArr(arr){if(arr.length === 0) return nulllet final = 0arr.forEach(num => {final += num})return final- "use strict";
- function addArr(arr) {
- return arr.length === 0
- ? null
- : arr.reduce((acc, x) => acc + x, 0);
- }
const chai = require("chai"); const assert = chai.assert; describe("Solution", function() { it("should test for something", function() { assert.strictEqual(addArr([1, 2, 3, 4, 5]), 15) assert.strictEqual(addArr([1, 100]), 101) assert.strictEqual(addArr([3]), 3) assert.strictEqual(addArr([]), null) }); });
- const chai = require("chai");
- const assert = chai.assert;
- describe("Solution", function() {
- it("should test for something", function() {
assert.strictEqual(addArr([1, 2, 3, 4, 5]), 15);- assert.strictEqual(addArr([1, 2, 3, 4, 5]), 15)
- assert.strictEqual(addArr([1, 100]), 101)
- assert.strictEqual(addArr([3]), 3)
- assert.strictEqual(addArr([]), null)
- });
- });