I'm doing a Ruby exercise to create new arrays with a given filter.
Copy the values less than 4 in the array stored in the
sourcevariable into the array in thedestinationvariable.
The editorial solution code is:
def array_copy(source)
destination = []
for number in source
# Add number to destination if number
# is less than 4
destination << number if number < 4
end
return destination
end
But, as a beginner, I came up with this solution:
def array_copy(source)
return source.select {|i| i < 4}
end
Is there any problems with my solution?