(array, compare)
| 155 | * @return {array} The sorted result. |
| 156 | */ |
| 157 | var StableSort = function (array, compare) |
| 158 | { |
| 159 | if (compare === undefined) { compare = Compare; } |
| 160 | |
| 161 | // Short-circuit when there's nothing to sort. |
| 162 | if (!array || array.length < 2) |
| 163 | { |
| 164 | return array; |
| 165 | } |
| 166 | |
| 167 | if (Device.features.stableSort) |
| 168 | { |
| 169 | return array.sort(compare); |
| 170 | } |
| 171 | |
| 172 | var result = Process(array, compare); |
| 173 | |
| 174 | // This simply copies back if the result isn't in the original array, which happens on an odd number of passes. |
| 175 | if (result !== array) |
| 176 | { |
| 177 | RunPass(result, null, array.length, array); |
| 178 | } |
| 179 | |
| 180 | return array; |
| 181 | }; |
| 182 | |
| 183 | module.exports = StableSort; |
no test coverage detected
searching dependent graphs…