feat: Modify sort with if/elseif/else randomize when the dates are equal (#10448)
Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
1 file changed
+4
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user