

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Smallest prime number just greater than the specified number in JavaScript
We are required to write a JavaScript function that takes in a positive integer as the first and the only argument.
The function should find one such smallest prime number which is just greater than the number specified as argument.
For example −
If the input is −
const num = 18;
Then the output should be:
const output = 19;
Example
Following is the code:
const num = 18; const justGreaterPrime = (num) => { for (let i = num + 1;; i++) { let isPrime = true; for (let d = 2; d * d <= i; d++) { if (i % d === 0) { isPrime = false; break; }; }; if (isPrime) { return i; }; }; }; console.log(justGreaterPrime(num));
Output
Following is the console output −
19
- Related Questions & Answers
- Kth prime number greater than N in C++
- How to find the smallest number greater than x in Python?
- JavaScript - Find the smallest n digit number or greater
- How to get the smallest integer greater than or equal to a number in JavaScript?
- Find Smallest Letter Greater Than Target in JavaScript
- Finding nearest prime to a specified number in JavaScript
- Returning just greater array in JavaScript
- Is the reversed number a prime number in JavaScript
- JavaScript Recursion finding the smallest number?
- Java Program to display a prime number less than the given number
- Getting equal or greater than number from the list of numbers in JavaScript
- JavaScript: Finding nearest prime number greater or equal to sum of digits - JavaScript
- Finding the smallest fitting number in JavaScript
- Find Smallest Letter Greater Than Target in Python
- Find smallest element greater than K in Python
Advertisements