mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 07:01:18 +08:00
Add factorial.
This commit is contained in:
parent
a10009df64
commit
3e5e78d291
@ -1,4 +1,5 @@
|
|||||||
import permutateWithoutRepetitions from '../permutateWithoutRepetitions';
|
import permutateWithoutRepetitions from '../permutateWithoutRepetitions';
|
||||||
|
import factorial from '../../../math/factorial/factorial';
|
||||||
|
|
||||||
describe('permutateString', () => {
|
describe('permutateString', () => {
|
||||||
it('should permutate string', () => {
|
it('should permutate string', () => {
|
||||||
@ -23,7 +24,7 @@ describe('permutateString', () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const permutations3 = permutateWithoutRepetitions('ABC');
|
const permutations3 = permutateWithoutRepetitions('ABC');
|
||||||
expect(permutations3.length).toBe(2 * 3);
|
expect(permutations3.length).toBe(factorial(3));
|
||||||
expect(permutations3).toEqual([
|
expect(permutations3).toEqual([
|
||||||
'CBA',
|
'CBA',
|
||||||
'BCA',
|
'BCA',
|
||||||
@ -34,7 +35,7 @@ describe('permutateString', () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const permutations4 = permutateWithoutRepetitions('ABCD');
|
const permutations4 = permutateWithoutRepetitions('ABCD');
|
||||||
expect(permutations4.length).toBe(2 * 3 * 4);
|
expect(permutations4.length).toBe(factorial(4));
|
||||||
expect(permutations4).toEqual([
|
expect(permutations4).toEqual([
|
||||||
'DCBA',
|
'DCBA',
|
||||||
'CDBA',
|
'CDBA',
|
||||||
@ -63,6 +64,6 @@ describe('permutateString', () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const permutations5 = permutateWithoutRepetitions('ABCDEF');
|
const permutations5 = permutateWithoutRepetitions('ABCDEF');
|
||||||
expect(permutations5.length).toBe(2 * 3 * 4 * 5 * 6);
|
expect(permutations5.length).toBe(factorial(6));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user