Skip to content

Instantly share code, notes, and snippets.

@himynameisdave
Created June 29, 2016 20:37
Show Gist options
  • Select an option

  • Save himynameisdave/2b36948f096bde5000d8a485e0dc1fd9 to your computer and use it in GitHub Desktop.

Select an option

Save himynameisdave/2b36948f096bde5000d8a485e0dc1fd9 to your computer and use it in GitHub Desktop.
Sort by a property in an array of objects
// Takes a property name and returns a function to be consumed by .sort
const sorter = (prop) => (a, b) => {
if (a[prop] < b[prop]) return -1;
if (a[prop] > b[prop]) return 1;
return 0;
};
export default sorter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment