Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
11
test/permutations/permutations.js
Normal file
11
test/permutations/permutations.js
Normal file
@ -0,0 +1,11 @@
|
||||
const permutations = arr => {
|
||||
if (arr.length <= 2) return arr.length === 2 ? [arr, [arr[1], arr[0]]] : arr;
|
||||
return arr.reduce(
|
||||
(acc, item, i) =>
|
||||
acc.concat(
|
||||
permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [item, ...val])
|
||||
),
|
||||
[]
|
||||
);
|
||||
};
|
||||
module.exports = permutations;
|
||||
10
test/permutations/permutations.test.js
Normal file
10
test/permutations/permutations.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const permutations = require('./permutations.js');
|
||||
|
||||
|
||||
test('permutations is a Function', () => {
|
||||
expect(permutations).toBeInstanceOf(Function);
|
||||
});
|
||||
t.deepEqual(permutations([1, 33, 5]), [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ], 'Generates all permutations of an array');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user