Apply a callback to an array: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 2,990: | Line 2,990: | ||
apply squaring (dup *) to each member of collection |
apply squaring (dup *) to each member of collection |
||
<lang v>[1 2 3 4] [dup *] map</lang> |
<lang v>[1 2 3 4] [dup *] map</lang> |
||
=={{header|VBA}}== |
|||
<lang vb> |
|||
Option Explicit |
|||
Sub Main() |
|||
Dim arr, i |
|||
'init |
|||
arr = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
|||
'Loop and apply a function (Fibonacci) to each element |
|||
For i = LBound(arr) To UBound(arr): arr(i) = Fibonacci(arr(i)): Next |
|||
'return |
|||
Debug.Print Join(arr, ", ") |
|||
End Sub |
|||
Private Function Fibonacci(N) As Variant |
|||
If N <= 1 Then |
|||
Fibonacci = N |
|||
Else |
|||
Fibonacci = Fibonacci(N - 1) + Fibonacci(N - 2) |
|||
End If |
|||
End Function</lang> |
|||
{{out}} |
|||
<pre>0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55</pre> |
|||
=={{header|VBScript}}== |
=={{header|VBScript}}== |