clojure-uebungen/Assignment_017/solution/readme.md

15 lines
378 B
Markdown
Raw Normal View History

2024-03-11 10:34:40 +01:00
# Lösung: filter
2024-03-11 10:32:49 +01:00
2024-03-11 10:39:04 +01:00
2024-03-11 10:41:23 +01:00
```clojure
(defn filter-positive
2024-03-11 10:39:04 +01:00
"Läuft über `data` und gibt die Elemente, deren Wert >= 0 ist zurück."
[data]
(filter #(>= % 0) data))
; Testfälle
(assert (= [1 2 3 4 0 5 6] (filter-positive [1 2 3 4 0 5 6])))
(assert (= [2 3] (filter-positive '(-1 2 3 -4))))
(assert (= [42 0 42] (filter-positive '(42 -23 0 -23 42))))
```