Ruby | Array repeated_combination() function
Last Updated :
06 Dec, 2019
Array#repeated_combination() : repeated_combination() is a Array class method which returns all repeated combinations of length n of elements from the array and then returns the array itself.
Syntax: Array.repeated_combination()
Parameter: Array
Return: all repeated combinations of length n of elements from the array and then returns the array itself.f.
Example #1 :
a = [ 18 , 22 , 33 , nil , 5 , 6 ]
b = [ 1 , 4 , 1 , 1 , 88 , 9 ]
c = []
puts "repeated_combination() method form :
puts "repeated_combination() method form :
puts "repeated_combination() method form :
|
Output :
repeated_combination() method form : [[18, 18], [18, 22], [18, 33], [18, nil], [18, 5], [18, 6], [22, 22], [22, 33], [22, nil], [22, 5], [22, 6], [33, 33], [33, nil], [33, 5], [33, 6], [nil, nil], [nil, 5], [nil, 6], [5, 5], [5, 6], [6, 6]]
repeated_combination() method form : [[1], [4], [1], [1], [88], [9]]
repeated_combination() method form : []
Example #2 :
a = [ "abc" , "nil" , "dog" ]
c = [ nil ]
b = [ "cow" , nil , "dog" ]
puts "repeated_combination() method form :
puts "repeated_combination() method form :
puts "repeated_combination() method form :
|
Output :
repeated_combination() method form : [["abc", "abc"], ["abc", "nil"], ["abc", "dog"], ["nil", "nil"], ["nil", "dog"], ["dog", "dog"]]
repeated_combination() method form : [["cow"], [nil], ["dog"]]
repeated_combination() method form : [[nil, nil, nil, nil]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...