reduce code size of recipes-by-ingredients by using 'filter'

This commit is contained in:
Christoffer Müller Madsen 2017-04-05 15:08:16 +02:00
parent 98648ee163
commit cc3cd7c19f

View File

@ -63,19 +63,5 @@
(define recipes-by-ingredients (define recipes-by-ingredients
(lambda (recipes search-ingredients) (lambda (recipes search-ingredients)
(recipes-by-ingredients-rec recipes search-ingredients '()))) (filter (lambda (x) (contains-ingredients? x search-ingredients))
recipes)))
(define recipes-by-ingredients-rec
(lambda (recipes search-ingredients list)
(if (null? recipes)
list
(let* ((recipe (car recipes))
(ingredients (ingredients recipe))
(contains? (contains-ingredients? recipe
search-ingredients))
(new-list (if contains?
(cons recipe list)
list)))
(recipes-by-ingredients-rec (cdr recipes)
search-ingredients
new-list)))))