UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

25 lines (24 loc) 674 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nextPrime = void 0; /** * Finds the next prime number after the given input. * @author @dailker * @param {number} n - The starting number. * @returns {number} The next prime. */ function nextPrime(n) { function isPrime(x) { if (x < 2) return false; for (let i = 2; i * i <= x; i++) if (x % i === 0) return false; return true; } let candidate = Math.max(2, Math.floor(n) + 1); while (!isPrime(candidate)) candidate++; return candidate; } exports.nextPrime = nextPrime;