I have an array like this:
[234, 235 , 343, 445]
I want to convert it to look like this
[[234],[235],[343],[445]]
Is there core library function in ruby 1.9.2 could help me to do this fast? and if not is there a fast way?
I did a small tests
def test1
array = []
10000000.times do
array << rand(1000000)
end
time = Time.now
array.permutation(1).to_a
puts "test1 (permutation) ---> Time = #{Time.now - time}"
end
def test2
array = []
10000000.times do
array << rand(1000000)
end
time = Time.now
array.zip()
puts "test2 (zip)---> Time = #{Time.now - time}"
end
def test3
array = []
10000000.times do
array << rand(1000000)
end
time = Time.now
array.map { |a| [a] }
puts "test3 (map) ---> Time = #{Time.now - time}"
end
test1 #test1 (permutation) ---> Time = 2.235128
test2 #test2 (zip) ---> Time = 1.537088
test3 #test3 (map) ---> Time = 2.230127