Removing commas

#1

arr = [[10,20,30],[40,50,60],[70,80,90]]

i need to remove comma’s
expected output should be: [[10,20,30][40,50,60][70,80,90]]

#2

You can’t do that, there’s no such thing as [[10,20,30][40,50,60][70,80,90]] in Ruby.

Yes, you can just display the values:

arr = [[10,20,30],[40,50,60],[70,80,90]]
print(*arr)    # writes `[10, 20, 30][40, 50, 60][70, 80, 90]'

Or you can create a string:

arr = [[10,20,30],[40,50,60],[70,80,90]]
"[#{arr.map { |x| "[#{x.join(', ')}]" }.join}]"    # => "[[10, 20, 30][40, 50, 60][70, 80, 90]]"

Hope this helps!

#3

There are many ways to accomplish that output…Ruby is very accommodating.

str = "["+arr.reduce(""){|acc, e| acc + e.to_s}+"]"

puts str => [[10, 20, 30][40, 50, 60][70, 80, 90]]
#4

Thanks! it worked for me