Ruby | Set flatten() function
The flatten() is an inbuilt method in Ruby returns a new set that is a copy of the set, flattening each containing set recursively.
Syntax: s1.flatten()
Parameters: The function does not takes any parameter.
Return Value: It returns a boolean value. It returns true if the set is empty or it returns false.
Example 1:
Ruby
require "set"
s1 = Set[ 1 , 2 , 4 , 4 ]
s2 = s1.flatten()
puts s2
|
Output:
Set: {1, 2, 4}
Example 2:
Ruby
require "set"
s1 = Set[ 16 , 8 , 3 , 5 , 2 ]
s2 = s1.flatten()
puts s2
|
Output:
Set: {16, 8, 3, 5, 2}
Last Updated :
04 Dec, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...