Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 9110f3f

Browse files
committed
Update README
1 parent 2625ce8 commit 9110f3f

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,17 @@ stableJsonStringify(obj); // '{"a":"baz","b":"foo","c":"bar"}'
108108

109109
#### Using a comparison function
110110

111-
If a comparison function is provided, it works the same as JavaScript's `Array.prototype.sort()` method. The two arguments, *a* and *b*, represent two successive key/value pairs in the form of `[key, value]`. A number is returned to indicate sort order as follows:
112-
* If a number less than zero is returned, *a* will precede *b*.
113-
* If a number greater than zero is returned, *b* will precede *a*.
114-
* If zero is returned, the original order will be maintained.
111+
If a comparison function is provided, it works the same as JavaScript's `Array.prototype.sort()` method. The two arguments, *a* and *b*, represent two successive object keys. A number is returned to indicate sort order as follows:
112+
* If a number less than `0` is returned, *a* will precede *b*.
113+
* If a number greater than `0` is returned, *b* will precede *a*.
114+
* If `0` is returned, the original order will be maintained.
115115

116116
```js
117117
const { stableJsonStringify } = require('@tuft/json-stringify');
118118

119119
// Sorts keys in descending alphabetical order.
120-
function compareFunction(entryA, entryB) {
121-
const [keyA] = entryA;
122-
const [keyB] = entryB;
123-
124-
return keyB.localeCompare(keyA);
120+
function compareFunction(keyA, keyB) {
121+
return a < b ? 1 : -1;
125122
}
126123

127124
const obj = {

0 commit comments

Comments
 (0)