![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Special type of numbers (pronic) in JavaScript
We are required to write a JavaScript function that takes in a number and returns true if it is a Pronic number otherwise returns false.
A Pronic number is a number which is the product of two consecutive integers, that is, a number of the form −
n(n + 1)
Example
The code for this will be −
const num = 132; const isPronic = num => { let nearestSqrt = Math.floor(Math.sqrt(num)) - 1; while(nearestSqrt * (nearestSqrt + 1) <= num){ if(nearestSqrt * (nearestSqrt+1) === num ){ return true; }; nearestSqrt++; }; return false; }; console.log(isPronic(num));
Output
The output in the console −
true
Advertisements