Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
11
test/orderBy/orderBy.js
Normal file
11
test/orderBy/orderBy.js
Normal file
@ -0,0 +1,11 @@
|
||||
const orderBy = (arr, props, orders) =>
|
||||
[...arr].sort((a, b) =>
|
||||
props.reduce((acc, prop, i) => {
|
||||
if (acc === 0) {
|
||||
const [p1, p2] = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]];
|
||||
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
|
||||
}
|
||||
return acc;
|
||||
}, 0)
|
||||
);
|
||||
module.exports = orderBy;
|
||||
11
test/orderBy/orderBy.test.js
Normal file
11
test/orderBy/orderBy.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const orderBy = require('./orderBy.js');
|
||||
|
||||
|
||||
test('orderBy is a Function', () => {
|
||||
expect(orderBy).toBeInstanceOf(Function);
|
||||
});
|
||||
const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }];
|
||||
t.deepEqual(orderBy(users, ['name', 'age'], ['asc', 'desc']), [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}], "Returns a sorted array of objects ordered by properties and orders.");
|
||||
t.deepEqual(orderBy(users, ['name', 'age']), [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}], "Returns a sorted array of objects ordered by properties and orders.");
|
||||
|
||||
Reference in New Issue
Block a user