← Back to challenges

Be Your Own Minifier

JavaScriptHardformattingloopsmathalgorithms

Instructions

Your boss has demanded you write a function to determine whether a given number n is prime or not. But there's a catch! The Blueberry Cæk™ you're using is a (rather extreme) discount model, and only has code storage space for a single line of code, and no more than the length of an old Tweet (140 characters).

Can you still make a working function?

(Re-)write the function isPrime() so that:

  • It works! It must correctly return true or false depending on whether the number provided is prime or not.
  • It takes up only a single line of code.
  • It uses no more than 140 characters.

Notes:

  • For the sake of this test, all numbers will be integers larger than 2. This is done so you won't need specific edge cases to deal with the weird cases of 2, which is prime, despite being even, and 1, which is not prime, despite fitting the "divisible only by 1 and itself" criterion.
  • Bonus: can you get the function to run in O(√n) time (instead of O(n))? (Note: You won't actually receive any bonus points for this)
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.