Skip to content

Commit 9e5041a

Browse files
committed
feat(permutations): remove unnecessary utility helper function that is replaceable with toEqual
1 parent 1eebb5d commit 9e5041a

File tree

1 file changed

+37
-62
lines changed

1 file changed

+37
-62
lines changed
Lines changed: 37 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,57 @@
1-
const permutations = require('./permutations-solution');
1+
const permutations = require("./permutations-solution");
22

3-
describe('permutations', () => {
4-
function outcome(input, expected) {
5-
const actual = permutations(input);
6-
7-
// Convert both arrays to strings to compare them later, excluding the order the arrays elements are in
8-
9-
const sterilise = (input) =>
10-
input
11-
.map((el) => el.toString())
12-
.toSorted()
13-
.toString();
14-
15-
return [sterilise(actual), sterilise(expected)];
16-
}
17-
18-
let actual, expected;
19-
20-
afterEach(() => {
21-
expect(actual).toBe(expected);
22-
});
23-
24-
test('Works for array of size one', () => {
25-
[actual, expected] = outcome([1], [1]);
3+
describe("permutations", () => {
4+
test("Works for array of size one", () => {
5+
expect(permutations([1]).sort()).toEqual([1].sort());
266
});
27-
test('Works for array of size two', () => {
28-
[actual, expected] = outcome(
29-
[1, 2],
7+
test("Works for array of size two", () => {
8+
expect(permutations([1, 2]).sort()).toEqual(
309
[
3110
[1, 2],
3211
[2, 1],
33-
],
12+
].sort(),
3413
);
3514
});
36-
test('Works for array of size three', () => {
37-
[actual, expected] = outcome(
38-
[1, 2, 3],
15+
test("Works for array of size three", () => {
16+
expect(permutations([1, 2, 3]).sort()).toEqual(
3917
[
4018
[1, 2, 3],
4119
[1, 3, 2],
4220
[2, 1, 3],
4321
[2, 3, 1],
4422
[3, 1, 2],
4523
[3, 2, 1],
46-
],
24+
].sort(),
4725
);
4826
});
49-
test('Works for array of size four', () => {
50-
[actual, expected] = outcome(
51-
[1, 2, 3, 4],
27+
test("Works for array of size four", () => {
28+
expect(permutations([1, 2, 3, 4]).sort()).toEqual(
5229
[
53-
[
54-
[1, 2, 3, 4],
55-
[1, 2, 4, 3],
56-
[1, 3, 2, 4],
57-
[1, 3, 4, 2],
58-
[1, 4, 2, 3],
59-
[1, 4, 3, 2],
60-
[2, 1, 3, 4],
61-
[2, 1, 4, 3],
62-
[2, 3, 1, 4],
63-
[2, 3, 4, 1],
64-
[2, 4, 1, 3],
65-
[2, 4, 3, 1],
66-
[3, 1, 2, 4],
67-
[3, 1, 4, 2],
68-
[3, 2, 1, 4],
69-
[3, 2, 4, 1],
70-
[3, 4, 1, 2],
71-
[3, 4, 2, 1],
72-
[4, 1, 2, 3],
73-
[4, 1, 3, 2],
74-
[4, 2, 1, 3],
75-
[4, 2, 3, 1],
76-
[4, 3, 1, 2],
77-
[4, 3, 2, 1],
78-
],
79-
],
30+
[1, 2, 3, 4],
31+
[1, 2, 4, 3],
32+
[1, 3, 2, 4],
33+
[1, 3, 4, 2],
34+
[1, 4, 2, 3],
35+
[1, 4, 3, 2],
36+
[2, 1, 3, 4],
37+
[2, 1, 4, 3],
38+
[2, 3, 1, 4],
39+
[2, 3, 4, 1],
40+
[2, 4, 1, 3],
41+
[2, 4, 3, 1],
42+
[3, 1, 2, 4],
43+
[3, 1, 4, 2],
44+
[3, 2, 1, 4],
45+
[3, 2, 4, 1],
46+
[3, 4, 1, 2],
47+
[3, 4, 2, 1],
48+
[4, 1, 2, 3],
49+
[4, 1, 3, 2],
50+
[4, 2, 1, 3],
51+
[4, 2, 3, 1],
52+
[4, 3, 1, 2],
53+
[4, 3, 2, 1],
54+
].sort(),
8055
);
8156
});
8257
});

0 commit comments

Comments
 (0)