Sort an object's keys by comparing their respective values.
Time complexity: O(n)
Space complexity: O(1)
Object to sort
Function used to compare object values
A new object with the keys in order
Sort
import { Sort } from '@jonahsnider/util';const object = { a: 3, c: 1, b: 2 };Object.fromEntries(sortObject(object, Sort.ascending)); Copy
import { Sort } from '@jonahsnider/util';const object = { a: 3, c: 1, b: 2 };Object.fromEntries(sortObject(object, Sort.ascending));
Sort an object's keys by comparing their respective values.
Time complexity: O(n)
Space complexity: O(1)