sortDeep

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.object

Sort an object properties the same way as the Array.sort do it but will do it recusrively to sort the object deeply.

Params

  1. object*-Object

    The object to sort

  2. sort*-Function

    The sort function to use

Return

  1. -Object

    The sorted object

Example

import { sortDeep } from '@blackbyte/sugar/object';
sortDeep({
   lolo: { weight: 2 },
   coco: { weight: 10 },
   plop: { weight: 5 },
   aha: {
     hello: 'world',
     coco: 'plop'
   }
}, (a, b) => {
   return a.key.localeCompare(b.key);
});
// {
//   aha: {
//      coco: 'plop',
//      hello: 'world'
//   }
//   coco: { weight: 10 }
//   lolo: { weight: 2 },
//   plop: { weight: 5 },
// }

Todo

  • testsnormal