हमें एक जावास्क्रिप्ट फंक्शन लिखना है जो एक नंबर ले और यदि यह प्रोनिक नंबर है तो true वापस करे अन्यथा false।
एक प्रोनिक नंबर वह नंबर है जो दो लगातार इंटीजर्स का गुणनफल है, यानी इस रूप का नंबर:
n(n + 1)
उदाहरण
इसके लिए कोड:
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));आउटपुट
कंसोल में आउटपुट:
true