Time complexity: O(sqrt(n))
Space complexity: O(1)
const isPrime = num => {
for(let i = 2, s = Math.sqrt(num); i <= s; i++)
if(num % i === 0) return false;
return num > 1;
}
More Related Contents:
- Link to a file and javascript simultaneously
- how to parse json array
- Pure JavaScript equivalent of jQuery’s $.ready() – how to call a function when the page/DOM is ready for it [duplicate]
- How to extend Function with ES6 classes?
- React.js: onChange event for contentEditable
- jQuery map vs. each
- javascript es6 array feature […data, 0] “spread operator”
- Javascript: closure of loop?
- Advanced JavaScript: Why is this function wrapped in parentheses? [duplicate]
- Which Logic Operator Takes Precedence
- Javascript Debugging line by line using Google Chrome
- Add 10 seconds to a Date
- Wrap tags around http text
- How to read response headers in angularjs?
- CSS Animation onClick
- Is there a way to send CoffeeScript to the client’s browser and have it compiled to JavaScript *there*?
- useEffect does not listen for localStorage
- How do I store javascript functions in a queue for them to be executed eventually [duplicate]
- Why use semicolon? [duplicate]
- Get the domain name of the subdomain Javascript
- how to set displayName in a functional component [React]
- Can I determine if a string is a MongoDB ObjectID?
- VSCODE: No debug adapter, can not send ‘variables'”
- Disable zoom on input focus in Android webpage
- Add a delay after executing each iteration with forEach loop
- How to download fetch response in react as file
- Is there a way to measure string similarity in Google BigQuery
- Firebase Custom Claims doesn’t propagate
- simplest cross-browser check if protocol handler is registered
- Delay script loading