We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2ee578c commit ffcf7c2Copy full SHA for ffcf7c2
50-powx-n.js
@@ -17,6 +17,23 @@ const myPow = function(x, n) {
17
18
// another
19
20
+/**
21
+ * @param {number} x
22
+ * @param {number} n
23
+ * @return {number}
24
+ */
25
+const myPow = function(x, n) {
26
+ if(n === 0) return 1
27
+ if(n === 1) return x
28
+ if(n < 0) {
29
+ x = 1 / x
30
+ n = -n
31
+ }
32
+ return n % 2 === 1 ? myPow(x, ~~(n / 2)) ** 2 * x : myPow(x, ~~(n / 2)) ** 2
33
+};
34
+
35
+// another
36
37
/**
38
* @param {number} x
39
* @param {number} n
0 commit comments