FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
DataStructure-Algorithm-TS/Algorithm/Recursion/Pow.js at master · Reaper622/DataStructure-Algorithm-TS · GitHub
Reaper622
/
DataStructure-Algorithm-TS
Public
Notifications
You must be signed in to change notification settings
Fork
16
Star
62
Code
Issues
0
Pull requests
17
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
DataStructure-Algorithm-TS
/
Algorithm
/
Recursion
/
Pow.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (33 loc) · 625 Bytes
Breadcrumbs
DataStructure-Algorithm-TS
/
Algorithm
/
Recursion
/
Pow.js
Copy path
File metadata and controls
33 lines (33 loc) · 625 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict"
;
exports
.
__esModule
=
true
;
/**
* 实现求幂的功能
*
@param
{
number
} x
*
@param
{
number
} n
*/
function
Pow
(
x
,
n
)
{
// 对特殊情况和边界进行处理
if
(
n
===
0
)
{
return
1
;
}
else
if
(
n
===
1
)
{
return
x
;
}
// 如果指数为负数
if
(
n
<
0
)
{
if
(
x
===
0
)
{
throw
new
Error
(
'0不能求倒数'
)
;
}
else
{
x
=
1
/
x
;
n
=
-
n
;
}
}
if
(
n
%
2
===
0
)
{
return
Pow
(
x
*
x
,
n
/
2
)
;
}
else
{
return
Pow
(
x
*
x
,
Math
.
floor
(
n
/
2
)
)
*
x
;
}
}
exports
.
Pow
=
Pow
;
Back
|
FazBrowse Home
|
New Git URL