feat: add List.where method for filtering elements with predicate function
Implement a `where` method on the List class that takes a predicate function and returns a new list containing only elements for which the predicate returns true. The implementation iterates over the list, calls the predicate on each element, and collects matching elements into a new list. Includes test cases verifying filtering with both matching and non-matching predicates.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
var a = [1, 2, 3]
|
||||
var moreThan1 = fn (x) { return x > 1 }
|
||||
var moreThan10 = fn (x) { return x > 10 }
|
||||
var b = a.where(moreThan1)
|
||||
var c = a.where(moreThan10)
|
||||
|
||||
IO.print(b) // expect: [2, 3]
|
||||
IO.print(c) // expect: []
|
||||
Reference in New Issue
Block a user