The reject() of enumerable is an inbuilt method in Ruby returns the items in the enumerable which does not satisfies the given condition in the block. It returns an enumerator if no block is given.
Syntax: enu.reject { |obj| block }
Parameters: The function takes a block whose condition is used to find the elements.
Return Value: It returns the items in the enum which does not satisfies the condition in the block. It returns an enumerator if no block is given.
Example #1:
enu = ( 1 .. 10 )
enu.reject { |obj| obj % 2 == 1 }
|
Output:
[2, 4, 6, 8, 10]
Example #2:
enu = [ 1 , 7 , 10 , 11 ]
enu.reject
|
Output:
Enumerator: [1, 7, 10, 11]:reject
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!