Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; (space-added-list L) consumes a non-empty (listof Str) and return the list
- ;; with a space added at the beginning of each word other than the first one
- ;; space-added-list : (listof Str) -> (listof Str)
- ;; Example :
- (check-expect (space-added-list (list "Hello" "how" "are" "you?"))
- (list "Hello" " how" " are" " you?"))
- (define (space-added-list L)
- (append (list (first L))
- (map (lambda (x) (string-append " " x)) (rest L))))
- ;; (join L) consumes a non-empty (listof Str), and returns the Str that results
- ;; from appending all the values in L, with a space (" ") between them
- ;; join : (listof Str) -> Str
- ;; requires : L is a non-empty list
- ;; Example :
- (check-expect (join (list "Hello" "how" "are" "you?")) "Hello how are you?")
- (define (join L)
- (foldr string-append "" (space-added-list L)))
- ;; Tests :
- (check-expect (join (list "I" "am" "fine" "thanks!")) "I am fine thanks!")
- (check-expect (join (list "How" "is" "your" "job?")) "How is your job?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement