Source

Variation of CodeAbbey problem 1: Sum A+B

Description

Given an array of numbers ns, return their sum.

1
[1, -1, 2, 7, 9, 124] ⟹ 142

My solution

1
2
3
4
5
6
7
#lang racket

(define (sum ns)
    (foldr + 0 ns))


(provide sum)

Tests

1
2
3
4
5
6
7
8
9
10
11
12
13
#lang racket

(require rackunit rackunit/text-ui "sum.rkt")

(define sum-tests
  (test-suite "sum tests"

    (test-case "Should return the sum"
        (check-equal? (sum (list 1 -1 2 7 9 124)) 142))

    ))

(run-tests sum-tests)