40 lines
836 B
Plaintext
40 lines
836 B
Plaintext
Sub map(f As Function(As Integer) As Integer, arr() As Integer, result() As Integer)
|
|
For i As Integer = Lbound(arr) To Ubound(arr)
|
|
result(i) = f(arr(i))
|
|
Next i
|
|
End Sub
|
|
|
|
Function timestwo(n As Integer) As Integer
|
|
Return n * 2
|
|
End Function
|
|
|
|
Function squared(n As Integer) As Integer
|
|
Return n ^ 2
|
|
End Function
|
|
|
|
Sub printArray(arr() As Integer)
|
|
For i As Integer = Lbound(arr) To Ubound(arr)
|
|
Print arr(i);
|
|
If i < Ubound(arr) Then Print ",";
|
|
Next i
|
|
Print
|
|
End Sub
|
|
|
|
Dim As Integer arr1(3) = {0, 1, 2, 3}
|
|
Dim As Integer arr2(3) = {2, 4, 6, 8}
|
|
Dim As Integer result(3)
|
|
|
|
map(@timestwo, arr1(), result())
|
|
printArray(result())
|
|
|
|
map(@squared, arr1(), result())
|
|
printArray(result())
|
|
|
|
map(@timestwo, arr2(), result())
|
|
printArray(result())
|
|
|
|
map(@squared, arr2(), result())
|
|
printArray(result())
|
|
|
|
Sleep
|