Created
May 21, 2024 12:39
-
-
Save JeffreyMFarley/daf609795f9ecd82d7c825023e948b70 to your computer and use it in GitHub Desktop.
Ordering a status list in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const order = ["FAILED", "COMPLETED", "RUNNING", "PENDING"]; | |
const grouped = insights.reduce( | |
(map, o) => map.set(o.status, (map.get(o.status.toUpperCase()) || []).concat(o)), new Map | |
); | |
const result = order.flatMap(status => grouped.get(status) || []); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment