Intro to the Big-O Notation

OPTION 1:def prime?(n)
return false if n <= 1
if (2...n).any?{|x| n % x== 0}
false
else
true
end
end
OPTION 2:def prime?(n)
(2...n).none? { |x| n % x == 0 }
end
OPTION 1 implementation, calculating the runtime with Ruby’s built in Time method
OPTION 2 implementation, calculating the runtime with Ruby’s built in Time method.

--

--

--

Fullstack Software Engineer | Musician | Food Lover | Coffee Addict

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Setup 2 Hyper-V 2016 Servers, enable Hyper-V Replica with self-created certificates and connect to…

Kolide Fleet on AWS Fargate: a Quick-Start guide

Indorse (IND) is now available on Kyber Network

What is a Graph Dtabase? Why choose Neo4J among the other Graph Databases

When, how, and why you should call Haskell functions from C

MongoDB with Docker: Get started in 5 minutes

How we cloned Nature’s Basket using MERN Stack

The rise of Declarative UI patterns

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Grace Yuiko Nakano

Grace Yuiko Nakano

Fullstack Software Engineer | Musician | Food Lover | Coffee Addict

More from Medium

The Database Lifecycle: Re-engineering the early stages of a startup’s database

10 Incredible places in Transylvania and best-hidden gems to visit in 2022

Role Of Stacks and Queue in Problem Solving

Furnace and AC Usage based on Calgary Average Daily Temperature and other Parameters (e.g.