MCPcopy Create free account
hub / github.com/dop251/goja / sortCompare

Method sortCompare

builtin_array.go:1763–1805  ·  view source on GitHub ↗
(x, y Value)

Source from the content-addressed store, hash-verified

1761}
1762
1763func (a *arraySortCtx) sortCompare(x, y Value) int {
1764 if x == nil && y == nil {
1765 return 0
1766 }
1767
1768 if x == nil {
1769 return 1
1770 }
1771
1772 if y == nil {
1773 return -1
1774 }
1775
1776 if x == _undefined && y == _undefined {
1777 return 0
1778 }
1779
1780 if x == _undefined {
1781 return 1
1782 }
1783
1784 if y == _undefined {
1785 return -1
1786 }
1787
1788 if a.compare != nil {
1789 f := a.compare(FunctionCall{
1790 This: _undefined,
1791 Arguments: []Value{x, y},
1792 }).ToFloat()
1793 if f > 0 {
1794 return 1
1795 }
1796 if f < 0 {
1797 return -1
1798 }
1799 if math.Signbit(f) {
1800 return -1
1801 }
1802 return 0
1803 }
1804 return x.toString().CompareTo(y.toString())
1805}
1806
1807// sort.Interface
1808

Callers 1

LessMethod · 0.95

Calls 3

ToFloatMethod · 0.65
CompareToMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected