-
Notifications
You must be signed in to change notification settings - Fork 1
Converted
ricardoboss edited this page Sep 13, 2023
·
1 revision
converted
returns a new list with the elements converted using the given callback.
converted(list subject, function callback)
-
subject
is the list to be converted. -
callback
is the function to be called for each element in the list.
The function must either have one parameter or two parameters whereas the second parameter must accept a number.
- If the callback has one parameter, the parameter will be the current element in the list.
- If the callback has two parameters, the first parameter will be the current element in the list and the second parameter will be the index of the current element in the list.
converted([1, 2, 3], (number n) {
return n * 2
}) // returns [2, 4, 6]
converted([1, 2, 3], (number n, number i) {
return n * i
}) // returns [0, 2, 6]
converted([1, 2, 3], (number n, number i) {
return "The " + (i + 1) + ". number is " + n
}) // returns ["The 1. number is 1", "The 2. number is 2", "The 3. number is 3"]
© 2023 Ricardo Boss • Licensed under MIT • Want to update this page? Edit it on GitHub and submit a pull request!