I have an array of strings "A" and a target string "B". The B string contains only characters from a to z and does not contain spaces. I need a ruby function that returns the array of strings which represents all possible ways to form B from elements of Array A. The order in which combinations are returned is irrelevant. Words from A can be used multiple times.
Example:
A = [‘x’, ‘y’, ‘z’, 'yz',‘xy’, ‘xyz’]
B = ‘xyz’
method(A, B) => [x y z, x yz, xyz, xy z]
I looked into permutation method but can't get it to work.