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

The key points of repository implementation on Laravel

DEV yVault Launches at Yearn Finance V2

Spring Framework Tutorial: Getting Started With Spring

Claim Exclusive Pepemons with Card Staking

How to Build an Automated, Large-Scale Fax Survey Campaign using Python, docx-mailmerge, and Phaxio

Picture1

CI Pipeline (Part 1): Understanding Pipelines

OpenFaaS Tutorial: Build and Deploy Serverless Java Functions

Codewars: Valid Parentheses

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

Training an autonomous pilot for the DonkeyCar

How to Build a Brand Using Jewelry Box Model

Privacy and Data Use

Daily links of Fernand0 — Enlaces diarios de Fernand0 — Issue #362