Skip to content

Commit 9321b14

Browse files
authored
Merge pull request #7 from vince19972/master
added power function
2 parents 0655d71 + 96bcd10 commit 9321b14

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

sketch.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ function anomalyCode(x) {
2929
return '5' + x - x;
3030
}
3131

32+
function anomalyCode(x) {
33+
return '5' + x - x;
34+
}
35+
36+
function power(base, exponent) {
37+
return Math.pow(base, exponent);
38+
}
39+
3240
function nOfFibonacci(x) {
3341
let n = parseInt(x, 10);
3442
return (!n || n < 1) ? -1 : (n < 3 ? 1 : (nOfFibonacci(n-1) + nOfFibonacci(n-2)));
@@ -43,5 +51,6 @@ module.exports = {
4351
sayHelloTo: sayHelloTo,
4452
answer: answer,
4553
anomalyCode: anomalyCode,
54+
power: power,
4655
nOfFibonacci: nOfFibonacci
4756
}

sketch.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, nOfFibonacci } = require('./sketch');
1+
const { sum, sub, prod, digital_root, sum42, sayHelloTo, anomalyCode, power, nOfFibonacci } = require('./sketch');
22
const fs = require("fs");
33
const path = require("path");
44
const fetch = require("node-fetch");
@@ -97,6 +97,10 @@ test('anomalyCode thousand should be 50000', () => {
9797
expect(anomalyCode(7891)).toBe(50000);
9898
})
9999

100+
test('power of one number', () => {
101+
expect(power(2, 2)).toBe(4);
102+
})
103+
100104
test('the 20th number of fibonacci should be 6765', () => {
101105
expect(nOfFibonacci(20)).toBe(6765);
102106
})

0 commit comments

Comments
 (0)