Ruby - create array by multiplying set of occurrences

Viewed 196

I want to create an array of size of 100 such that the values will appear X number of occurrences defined in another array.

So the below arrays:

arr1 = ['text1', 'text2', 'text3', 'text4', 'text5', 'text6']
arr2 = [5, 5, 10, 10, 20, 50] 

Will create a new array that contains 5 times the value 'text1', 50 times the value 'text6', etc.

3 Answers
Related