sort

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. The “a” and “b” argument passed to your sort function will have these properties:

  • key: The key of the object
  • value: The actual value of the object property

Params

  1. object*-Object

    The object to sort

  2. sortnullFunction

    The sort function to use. If not specified, will sort the items by key alphabetically

Return

  1. -Object

    The sorted object

Example

import { sort } from '@blackbyte/sugar/object';
sort({
   coco: { weight: 10 },
   lolo: { weight: 2 },
   plop: { weight: 5 }
}, (a, b) => {
  return a.value.weight - b.value.weight;
});
// {
//   lolo: { weight: 2 },
//   plop: { weight: 5 },
//   coco: { weight: 10 }
// }

Todo

  • testsnormal