shared
utils
string
object
is
extension
js
tracking
string
dom
when
selection
position
iframe
event
scroll
console
node
string
project
fs
console
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
- object*-Object
The object to sort
- sortnullFunction
The sort function to use. If not specified, will sort the items by key alphabetically
Return
- -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
Author
- Olivier Bosselolivier.bossel@gmail.comhttps://blackbyte.space