feat: Modify sort with if/elseif/else randomize when the dates are equal (#10448)
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>pull/10536/head^2
parent
1b6d1b3a5a
commit
2de4abba65
|
@ -92,7 +92,10 @@ async function leastRecentlyBookedUser<T extends Pick<User, "id" | "email">>({
|
|||
}
|
||||
|
||||
const leastRecentlyBookedUser = availableUsers.sort((a, b) => {
|
||||
return userIdAndAtCreatedPair[a.id] > userIdAndAtCreatedPair[b.id] ? 1 : -1;
|
||||
if (userIdAndAtCreatedPair[a.id] > userIdAndAtCreatedPair[b.id]) return 1;
|
||||
else if (userIdAndAtCreatedPair[a.id] < userIdAndAtCreatedPair[b.id]) return -1;
|
||||
// if two (or more) dates are identical, we randomize the order
|
||||
else return Math.random() > 0.5 ? 1 : -1;
|
||||
})[0];
|
||||
|
||||
return leastRecentlyBookedUser;
|
||||
|
|
Loading…
Reference in New Issue