Closed gvlasov closed 5 years ago
Sorts an array by the value of a function of its elements:
sortBy( ["Bob","Jake","Ed","Murphy"], function($elem, $index, $collection) { return strlen($elem); } ); // ["Ed", "Bob", "Jake", "Murphy"] Analogous to: sort( ["Bob","Jake","Ed","Murphy"], function($left, $right) { return strlen($left) - strlen($right); } );
Sounds like a plausible use case, especially if one wants to sort a list of objects by e.g. a weight property. Would you you be interested in working on a PR?
Closing for inactivity
Sorts an array by the value of a function of its elements: