Created
June 29, 2016 20:37
-
-
Save himynameisdave/2b36948f096bde5000d8a485e0dc1fd9 to your computer and use it in GitHub Desktop.
Sort by a property in an array of objects
This file contains hidden or 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
| // 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