-
Code (ns arr-sum) (def arr-add (reduce + %))
Test Cases (ns arr-sum-test (:require [clojure.test :refer :all] [arr-sum :refer [arr-add]])) (deftest arr-add-test (is (arr-add (list 1 2 3 4 5 6 7 8 9)) (+ 1 2 3 4 5 6 7 8 9)) (is (arr-add (list 1 2 3 -4 5 6 7 8 9)) (+ 1 2 3 -4 5 6 7 8 9)))
Output:
-
Code function addArr(arr){if(arr.length === 0) return nulllet final = 0arr.forEach(num => {final += num})return final}- (ns arr-sum)
- (def arr-add #(reduce + %))
Test Cases 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([]), null)});});- (ns arr-sum-test
- (:require [clojure.test :refer :all]
- [arr-sum :refer [arr-add]]))
- (deftest arr-add-test
- (is
- (arr-add (list 1 2 3 4 5 6 7 8 9))
- (+ 1 2 3 4 5 6 7 8 9))
- (is
- (arr-add (list 1 2 3 -4 5 6 7 8 9))
- (+ 1 2 3 -4 5 6 7 8 9)))
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}