-
Notifications
You must be signed in to change notification settings - Fork 1
Filtered
ricardoboss edited this page Sep 13, 2023
·
1 revision
filtered
is a function that returns a list of items that match a given condition.
filtered(list subject, function callback)
-
subject
is the list to be filtered. -
callback
is a function that returns a boolean value. The function is called for each item in the list. If the function returnstrue
, the item is added to the result list. If the function returnsfalse
, the item is not added to the result list.
- The
callback
function must have one or two parameters and must return a boolean value. - If the
callback
function has one parameter, the parameter is the current item in the list. - If the
callback
function has two parameters, the first parameter is the current item in the list and the second parameter is the index of the current item in the list.
filtered([1, 2, 3, 4, 5], (number item) {
return item % 2 == 0
}) // returns [2, 4]
filtered([1, 2, 3, 4, 5], (number item, number index) {
return index % 2 == 0
}) // returns [1, 3, 5]
© 2023 Ricardo Boss • Licensed under MIT • Want to update this page? Edit it on GitHub and submit a pull request!