हमें एक जावास्क्रिप्ट फ़ंक्शन लिखना है जो दो नंबर लेता है, मान लीजिए num1 और num2।
-
अगर num1, num2 से बड़ा है, तो हमारा फंक्शन और बड़ा होना चाहिए।
-
अगर num2 num1 से बड़ा है, तो हमारा फंक्शन छोटा होना चाहिए।
-
अन्यथा, फ़ंक्शन बराबर लौटना चाहिए।
उदाहरण
निम्नलिखित कोड है -
const compareIntegers = (num1, num2) => {
if(typeof num1 !== 'number' || typeof num2 !== 'number'){
return false;
};
if(num1 > num2){
return 'greater';
}else if(num2 > num1){
return 'smaller';
}else{
return 'equal';
};
};
console.log(compareIntegers(12, 56));
console.log(compareIntegers(72, 56));
console.log(compareIntegers(12, 12));
console.log(compareIntegers(12, 33)); आउटपुट
कंसोल पर आउटपुट निम्नलिखित है -
smaller greater equal smaller