Search code examples
rubyfindall

Ruby .find_all for numbers greater than x


I'm new to Ruby and struggling with something that should be very simple. Use .find_all to return the numbers greater than 10.

Here is what I've tried so far and the response I'm getting:

nums = [3,9,15,20]

I get the error message "syntax error, unexpected =>, expecting '}'" when I try the below:

nums.find_all { |x| x => 10 }

I can get numbers equal to or even/odd numbers to return when I try, but not greater than or less than. What am I doing wrong?


Solution

  • Greater than or equal to is >= and same, less than or equal to is <=

    nums.find_all { |x| x >= 10 }
     => [15, 20]
    
    
    nums.find_all { |x| x <= 10 }
     => [3, 9]