Next Prime

Published by Helen Yu in

Given an integer, create a function that returns the next prime. If the number is prime, return the number itself.

Examples

nextPrime(12) ➞ 13

nextPrime(24) ➞ 29

nextPrime(11) ➞ 11
// 11 is a prime, so we return the number itself.

Notes

Note: 1 is not a prime.

Watch a quick demo on how Edabit works.