Given an array, return it without its last element.
My solution
1
2
3
4
5
6
7
8
9
| #lang racket
(define (all-but-last lst)
"Return all but the last element of a list."
(take lst (- (length lst) 1)))
(provide all-but-last)
|
Tests
1
2
3
4
5
6
7
8
9
10
11
12
13
| #lang racket
(require rackunit rackunit/text-ui "all-but-last.rkt")
(define all-but-last-tests
(test-suite "all-but-last tests"
(test-case "Should return all but the last element"
(check-equal? (all-but-last '(1 2 3)) '(1 2)))
(check-equal? (all-but-last '("a" "b" "c")) '("a" "b")))
))
(run-tests all-but-last-tests)
|