To achieve the desired result, you can multiply each element of the array [1, 10, 100] by 3 using the map
method in Ruby. Here's how you can do it:
main.rb78 chars4 lines
The map
method applies the given block of code to each element of the array and returns a new array with the results. In this case, we multiply each element by 3, resulting in [3, 30, 300]. The inspect
method is used to display the resulting array.
Output:
main.rb13 chars2 lines
This code will give you the desired result.
gistlibby LogSnag