Two arrays:
a1 = ["a", "b", "c", "d", "e", "f"]
a2 = [1, 2, 3]
How to insert a2
into a1
, keeping the a2 order but in random indexes of a1?
(0..a1.length).to_a.sample(a2.length).sort
.zip(a2)
.reverse
.each{|i, e| a1.insert(i, e)}
Two arrays:
a1 = ["a", "b", "c", "d", "e", "f"]
a2 = [1, 2, 3]
How to insert a2
into a1
, keeping the a2 order but in random indexes of a1?
(0..a1.length).to_a.sample(a2.length).sort
.zip(a2)
.reverse
.each{|i, e| a1.insert(i, e)}