Given a string, return it reversed.
My solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| #lang racket
(define (reverse s)
(local [(define lstidx
(sub1 (string-length s)))]
(cond [(= 0 lstidx) s]
[else
(string-append
(substring s lstidx)
(reverse (substring s 0 lstidx)))])))
(provide reverse)
|
Tests
1
2
3
4
5
6
7
8
9
10
11
12
13
| #lang racket
(require rackunit rackunit/text-ui "reverse.rkt")
(define reverse-tests
(test-suite "reverse tests"
(test-case "Should return the string reversed"
(check-equal? (reverse "foobar") "raboof"))
))
(run-tests reverse-tests)
|