ran npm run tdd & generated TDD
This commit is contained in:
10
test/orderBy/orderBy.js
Normal file
10
test/orderBy/orderBy.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = (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)
|
||||
);
|
||||
Reference in New Issue
Block a user