Apply a callback to an array: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 1:
{{
Apply a callback function to each element of an Array
|
Revision as of 20:38, 22 January 2007
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Apply a callback function to each element of an Array
Ruby
#create the array ary = [1,2,3,4,5] #create the function (print the square) def print_square(i) puts i**2 end #ruby ary.each do |i| print_square(i) end # prints 1,4,9,16,25