MCPcopy Index your code
hub / github.com/buildbot/buildbot / applySort

Method applySort

www/data-module/src/data/DataQuery.ts:102–141  ·  view source on GitHub ↗
(array: any[])

Source from the content-addressed store, hash-verified

100 }
101
102 applySort(array: any[]) {
103 const order = this.order;
104 if (order === null) {
105 return;
106 }
107 const compare = (property: string) => {
108 let reverse = false;
109 if (property[0] === '-') {
110 property = property.slice(1);
111 reverse = true;
112 }
113
114 return (a: any, b: any) => {
115 if (reverse) {
116 [a, b] = Array.from([b, a]);
117 }
118
119 if (a[property] < b[property]) {
120 return -1;
121 } else if (a[property] > b[property]) {
122 return 1;
123 } else {
124 return 0;
125 }
126 };
127 };
128 if (typeof order === 'string') {
129 array.sort(compare(order));
130 } else if (Array.isArray(order)) {
131 array.sort((a: any, b: any) => {
132 for (let o of Array.from(order)) {
133 const f = compare(o)(a, b);
134 if (f) { return f; }
135 }
136 return 0;
137 });
138 } else {
139 throw Error(`Unsupported order parameter for query {order}`)
140 }
141 }
142
143 applyLimit(array: any[]) {
144 if (this.limit === null) {

Callers 2

sortMethod · 0.95
recomputeQueryMethod · 0.80

Calls 2

sortMethod · 0.80
ErrorClass · 0.50

Tested by 1

sortMethod · 0.76