Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. function sortShowAllBy<T>(arrayToSort: _Chain<T>, properties: string[]) {
  2. _.each(properties,(property) => {
  3. arrayToSort = arrayToSort.sortBy((currentObject) => { return getPropertyFromObject(currentObject, property) })
  4. });
  5.  
  6. return arrayToSort.value();
  7. }
  8.  
  9. function getPropertyFromObject(object: Object, property: string) {
  10.  
  11. //index of next property split
  12. var propertySplitIndex = property.indexOf('.')
  13.  
  14. //property split exists so do a recursive call
  15. if (propertySplitIndex > -1) {
  16. //get object at current property (before split), pass on remainder
  17. return getPropertyFromObject(object[property.substring(0, propertySplitIndex)], property.substr(propertySplitIndex + 1));
  18. }
  19. return object[property];
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement