Skip to content

Commit

Permalink
Reducing utility.sort() & fixing a reference error
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Dec 8, 2020
1 parent 3cfaffc commit 7d42d3a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ function hypermedia (req, res, rep) {
}

function sort (arg, req) {
let output;
let output = clone(arg);

if (typeof req.parsed.search === "string" && req.parsed.searchParams.has("order_by") && Array.isArray(arg)) {
const type = typeof arg[0];
Expand All @@ -645,17 +645,13 @@ function sort (arg, req) {
const args = req.parsed.searchParams.getAll("order_by").filter(i => i !== "desc").join(", ");

if (args.length > 0) {
output = keysort(clone(arg), args);
output = keysort(output, args);
}
} else {
output = clone(arg);
}

if (req.parsed.search.includes("order_by=desc")) {
output = output.reverse();
}
} else {
output = arg;
}

return output;
Expand Down

0 comments on commit 7d42d3a

Please sign in to comment.