filter

Filters an array

(filter fn arr)

Returns

A portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function

Parameters

fn (lambda) - a function to be run for each array element. It should return a truthy value

arr (array) - the array to be filtered

Examples

;; filter all values smaller then 2
(filter (fn [x] (> x 2)) [1, 2, 3, 4, 5])
;;=> [3, 4, 5, 6]

Was this helpful?