fixed an issue with default parameters

This commit is contained in:
Elder Henrique Souza
2017-12-20 11:03:50 -02:00
committed by GitHub
parent dbc3b9c452
commit 3d9538ef7e

View File

@ -10,7 +10,7 @@ const orderBy = (arr, props, orders) =>
arr.sort((a, b) =>
props.reduce((acc, prop, i) => {
if (acc === 0) {
const [p1, p2] = orders[i] === 'asc' ? [a[prop], b[prop]] : [b[prop], a[prop]];
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;