Tuesday, 9 July 2019

How to find a given number is prime or not in ruby?

def check_prime n
    (2..n-1).each do |no|
         return false if n % no == 0
    end
    true
end

No comments:

Post a Comment

Interactor in Rails

What is interactor? Interactor provides a common interface for performing complex user interactions An interactor is a simple, sin...