Skip to content

Instantly share code, notes, and snippets.

@ekajjake
Created November 25, 2013 18:32
Show Gist options
  • Save ekajjake/7646216 to your computer and use it in GitHub Desktop.
Save ekajjake/7646216 to your computer and use it in GitHub Desktop.
Potential Final Problem
;;list number -> list
;;the function takes in a list and a number and returns a list of the first n elements.
(define (take a-list n)
(cond [(= 0 n) empty]
[else (cons (first a-list) (take (rest a-list)(- n 1))) ]))
(check-expect (take (list "a" "b" "c" "d" "e") 3)(list "a" "b" "c"))
(check-expect (take (list "a" "b" "c" "d" "e") 2)(list "a" "b"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment