Skip to content

Commit

Permalink
Optimize sortPersons
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Jul 2, 2024
1 parent c1b4651 commit b15838c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils/ldap.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ function score (a, q) {
}

function sortPersons (obj, q) {
return obj.sort((a, b) =>
score(b, q) - score(a, q) ||
a.name.localeCompare(b.name) ||
a.firstname.localeCompare(b.firstname)
);
const scores = obj.map(a => ({ p: a, score: score(a, q) }));
return scores.sort((a, b) =>
b.score - a.score ||
a.p.name.localeCompare(b.p.name) ||
a.p.firstname.localeCompare(b.p.firstname)
).map(scores => scores.p);
}

/**
Expand Down

0 comments on commit b15838c

Please sign in to comment.