forked from WildCodeSchool/js-katas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
math-pow.js
34 lines (25 loc) · 859 Bytes
/
math-pow.js
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
34
/*
Create a function `pow` which given two arguments, base and exponent, returns the base to the exponent power, as in base^exponent.
The base and exponent will only have positive values (you don't need to check this).
If an argument is not a number, return NaN.
* pow(2, 0) -> 1
* pow(2, 1) -> 2
* pow(2, 2) -> 4
* pow(3, 3) -> 27
* pow("tacos", 2) -> NaN
* pow(42) -> NaN
You can't use Math.pow(), the goal is to recreate this function!
*/
// TODO add your code here
// Begin of tests
const assert = require("assert");
assert.strictEqual(typeof pow, "function");
assert.strictEqual(pow.length, 2);
assert.strictEqual(pow(2, 0), 1);
assert.strictEqual(pow(2, 1), 2);
assert.strictEqual(pow(2, 2), 4);
assert.strictEqual(pow(3, 3), 27);
assert.strictEqual(pow("tacos", 2), NaN);
assert.strictEqual(pow(42), NaN);
// End of tests
console.log("🎉");