समस्या
हमें एक जावास्क्रिप्ट फ़ंक्शन लिखना है जो एक संख्या लेता है। हमारा फ़ंक्शन निम्न का मान लौटाएगा:
(i)n
यहां,
i = -11/2
इसलिए,
i^2 = -1 i^3 = -i i^4 = 1 और इसी तरह
उदाहरण
निम्न कोड देखें:
const num = 657; const findNthPower = (num = 1) => { switch(num % 4){ case 0: return '1'; case 1: return 'i'; case 2: return '-1'; case 3: return '-i'; }; }; console.log(findNthPower(num));आउटपुट
i