MCPcopy
hub / github.com/TheAlgorithms/JavaScript / defaultComparator

Function defaultComparator

Sorts/IntroSort.js:31–40  ·  view source on GitHub ↗
(x, y)

Source from the content-addressed store, hash-verified

29 * 1 if a greater than b
30 */
31 const defaultComparator = function (x, y) {
32 if (x === undefined && y === undefined) return 0
33 if (x === undefined) return 1
34 if (y === undefined) return -1
35 const xString = toString(x)
36 const yString = toString(y)
37 if (xString < yString) return -1
38 if (xString > yString) return 1
39 return 0
40 }
41 /**
42 * @function helper function for defaultComparator
43 * Converts a given object to String

Callers

nothing calls this directly

Calls 1

toStringFunction · 0.85

Tested by

no test coverage detected