forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IsPronic.js
27 lines (25 loc) · 822 Bytes
/
IsPronic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* Author: Akshay Dubey (https://github.com/itsAkshayDubey)
* Pronic Number: https://en.wikipedia.org/wiki/Pronic_number
* function to check if number is pronic.
* return true if number is pronic.
* else false
*/
/**
* @function isPronic
* @description -> Checking if number is pronic using product of two consecutive numbers
* If number is a product of two consecutive numbers, then it is pronic
* therefore, the function will return true
*
* If number is not a product of two consecutive numbers, then it is not pronic
* therefore, the function will return false
* @param {number} number
* @returns {boolean}
*/
export const isPronic = (number) => {
if (number === 0) {
return true
}
const sqrt = Math.sqrt(number)
return sqrt % 1 !== 0 && Math.ceil(sqrt) * Math.floor(sqrt) === number
}