Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Created October 13, 2022 16:30
Show Gist options
  • Save zakuroishikuro/cabf700e1189db5b7d216534ba08320b to your computer and use it in GitHub Desktop.
Save zakuroishikuro/cabf700e1189db5b7d216534ba08320b to your computer and use it in GitHub Desktop.
const comp = (a, b) => +(a > b || (a < b && -1));
[{ id: "a" }, { id: "c" }, { id: "b" }].sort((a, b) => comp(a.id, b.id));
//=> [{ id: "a" }, { id: "b" }, { id: "c" }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment