Saturday, October 25, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

Return the next higher prime number

Published: February 11, 2022

Write a function that takes a number (a) as argument. If a is prime number, return a. If a is not prime number then return the next higher prime number.

const nextPrimeNumber = (num) => {
    for(let i = 2; i < num ; i++) {
        if(num % i === 0) {
            return nextPrimeNumber(num + 1)
        }

    }
    return num;
};

const input = 90;
console.log(nextPrimeNumber(input)); // 97

You May Also Like

Prefer dependency injection to hardwiring resources

January 22, 2020 beroza

How to remove the last element of array in JavaScript?

October 1, 2022 beroza

could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket

October 11, 2020 beroza

Constant or const when to use in JavaScript?

January 7, 2021 beroza

Binary search algorithm

March 15, 2022 beroza

Write a Program to Find N-ary Tree Preorder Traversal

January 8, 2023 beroza

What are the differences between properties and attributes in JavaScript?

August 31, 2021 beroza

What is useRef in React? What are the use cases of useRef?

August 14, 2021 beroza

error: variable might not have been initialized Java

November 14, 2019 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.