Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Created June 22, 2021 12:20
Show Gist options
  • Save AitorAlejandro/4ca2b46897d655e419183dc30d536d57 to your computer and use it in GitHub Desktop.
Save AitorAlejandro/4ca2b46897d655e419183dc30d536d57 to your computer and use it in GitHub Desktop.
Order list by boolean property and in a immutable way
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