
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return Value of Nth Power of Iota in JavaScript
Problem
We are required to write a JavaScript function that takes in a number. Our function should return the value of −
(i)n
Here,
i = -11/2
Therefore,
i^2 = -1 i^3 = -i i^4 = 1 and so on
Example
Following is the code −
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));
Output
i
Advertisements