Skip to content

Instantly share code, notes, and snippets.

@JeffreyMFarley
Created May 21, 2024 12:39
Show Gist options
  • Save JeffreyMFarley/daf609795f9ecd82d7c825023e948b70 to your computer and use it in GitHub Desktop.
Save JeffreyMFarley/daf609795f9ecd82d7c825023e948b70 to your computer and use it in GitHub Desktop.
Ordering a status list in Javascript
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