Created
November 25, 2013 18:55
-
-
Save JonTanS/7646648 to your computer and use it in GitHub Desktop.
Practice 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;list -> number | |
;takes in a list of numbers and returns the mean. | |
(define (damean litt) | |
(/ (halp litt) (lengtha litt))) | |
(define (halp litt) | |
(cond [(empty? litt) 0] | |
[else (+ (first litt) (halp (rest litt)))])) | |
(define (lengtha litt) | |
(cond [(empty? litt) 0] | |
[else (+ 1 (lengtha (rest litt)))])) | |
(check-expect (damean (list 1 2 3 4 5)) 3) | |
(check-expect (damean (list 1 1 1 1 1)) 1) | |
(check-expect (damean (list 0 1 2 3 4)) 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment