Hi Everyone,
Can anyone tell me how to return a two dimensional array from a
Function?
I tried “returning(value)” function, but it allows only single
dimensional array.
Thanks in advance.
Regards,
VASANTH
Hi Everyone,
Can anyone tell me how to return a two dimensional array from a
Function?
I tried “returning(value)” function, but it allows only single
dimensional array.
Thanks in advance.
Regards,
VASANTH
returning an array works fine for me:
def two_dimensional(size, val)
Array.new(size, Array.new(size, val))
end
two_dimensional(4,1)
=> [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
Mike
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs