Skip to content

Commit 3f32320

Browse files
committed
Comply with ESM. Convert live code example to Jest test.
1 parent cbe7e0c commit 3f32320

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

Diff for: Maths/PermutationAndCombination.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,4 @@ const combination = (n, r) => {
4747
}
4848

4949
// Exports the functions to be used in other files.
50-
module.exports.factorial = factorial
51-
module.exports.permutation = permutation
52-
module.exports.combination = combination
53-
54-
/**
55-
* @example
56-
57-
const funcs = require("./PermutationAndCombination.js");
58-
59-
console.log(funcs.factorial(5));
60-
console.log(funcs.permutation(5, 2));
61-
console.log(funcs.combination(5, 2));
62-
63-
* @output
64-
120
65-
20
66-
10
67-
*/
50+
export { factorial, permutation, combination }

Diff for: Maths/test/PermutationAndCombination.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { factorial, permutation, combination } from '../PermutationAndCombination'
2+
3+
describe('Factorial', () => {
4+
it('factorial(5)', () => {
5+
expect(factorial(5)).toBe(120)
6+
})
7+
})
8+
9+
describe('Permutation', () => {
10+
it('permutation(5, 2)', () => {
11+
expect(permutation(5, 2)).toBe(20)
12+
})
13+
})
14+
15+
describe('Combination', () => {
16+
it('combination(5, 2)', () => {
17+
expect(combination(5, 2)).toBe(10)
18+
})
19+
})

0 commit comments

Comments
 (0)