Skip to content

Commit 2b2c23d

Browse files
author
juanantonioledesma
committed
Add "Power" kata
1 parent 593f351 commit 2b2c23d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

8-kyu/power.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<h1>Power <sup><sup>8 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/562926c855ca9fdc4800005b">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>RESTRICTED</code>
7+
</sup>
8+
9+
## Description
10+
11+
The goal is to create a function of two inputs `number` and `power`, that "raises" the `number` up to `power` (ie multiplies `number` by itself `power` times).
12+
13+
**Examples**
14+
15+
```
16+
numberToPower(3, 2) // -> 9 ( = 3 * 3 )
17+
numberToPower(2, 3) // -> 8 ( = 2 * 2 * 2 )
18+
numberToPower(10, 6) // -> 1000000
19+
```
20+
21+
**Note:** `Math.pow` and some other `Math` functions like eval() and `**` are disabled.
22+
23+
## Solution
24+
25+
```javascript
26+
const numberToPower = (number, power) => {
27+
let result = 1
28+
29+
for (let i = 0; i < power; i++) {
30+
result *= number
31+
}
32+
33+
return result
34+
}
35+
```

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
7272
- **[Multiply](./8-kyu/multiply.md)**
7373
- **[Object Oriented Piracy](./8-kyu/object-oriented-piracy.md)**
7474
- **[Opposites Attract](./8-kyu/opposites-attract.md)**
75+
- **[Power](./8-kyu/power.md)**

0 commit comments

Comments
 (0)