Created
June 22, 2021 12:20
-
-
Save AitorAlejandro/4ca2b46897d655e419183dc30d536d57 to your computer and use it in GitHub Desktop.
Order list by boolean property and in a immutable way
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
export function orderListByBooleanProperty({ list = [], propertyName = '', asc = true }) { | |
const immutableList = [...list]; | |
const sortedList = [...immutableList].sort(function (a, b) { | |
return asc ? a[propertyName] - b[propertyName] : b[propertyName] - a[propertyName]; | |
}); | |
return sortedList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment