Skip to content

Instantly share code, notes, and snippets.

@ancms2600
Created May 18, 2018 17:01
Show Gist options
  • Save ancms2600/471affc9a414718c90f6b9749d5da3e5 to your computer and use it in GitHub Desktop.
Save ancms2600/471affc9a414718c90f6b9749d5da3e5 to your computer and use it in GitHub Desktop.
Javascript sortBy multi-dimensional (e.g., `SORT BY state ASC, city ASC`)
const sortBy = (...k) => (a,b) => ((k)=> (null==k || a[k]===b[k]) ? 0 : a[k]<=b[k] ? -1 : 1 )(k.find(_k=>a[_k]!==b[_k]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment