ruby on rails - All variants of an array -


I have an array that is structured like this:

  array = ["one two three four"];  

How can I get all the possible types of this array, 1-4: possibly at all lengths:

  ar = [[ "" ["One", "three", "four"]  / formerly "" ["one", "three", "two"] ["one", "three" 

I think 4 * 4 * 4 * 4 elements should be in the array at the end.

< Blockquote>

How can I get all the possible forms of this array [...]

Use:

  array.combination (3) .to_a  

Result:

  [["one", " ("One", "three", "four"), ["two", "three", "four"]], "three"], ["one", "two", "four"]  

[..] All possible lengths 1-4

Use a category, iterate with:

  (1..array.length) .flat_map {| lane | array (len) .to_a}  

Result:

 < ["One", "four"], ["two", "three"], ["one"], ["two"], ["three"] ["one", "three"], ["Two", "four"], ["three", "four"], ["one", "two", "three"], ["one", "two" ["One", "two", "four"], ["one", "four"], ["one", "three", "four"], ["two", "three" Three "/ div>  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -