| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 this.swarming = this.swarming || function() { | 5 this.swarming = this.swarming || function() { |
| 6 | 6 |
| 7 var swarming = {}; | 7 var swarming = {}; |
| 8 | 8 |
| 9 swarming.stableSort = function(arr, comp) { | 9 swarming.stableSort = function(arr, comp) { |
| 10 if (!arr || !comp) { | 10 if (!arr || !comp) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 // naturalCompare tries to use natural sorting (e.g. sort ints by value). | 42 // naturalCompare tries to use natural sorting (e.g. sort ints by value). |
| 43 swarming.naturalCompare = function(a, b) { | 43 swarming.naturalCompare = function(a, b) { |
| 44 // Try numeric, aka "natural" sort and use it if ns is not NaN. | 44 // Try numeric, aka "natural" sort and use it if ns is not NaN. |
| 45 // Javascript will try to corece these to numbers or return NaN. | 45 // Javascript will try to corece these to numbers or return NaN. |
| 46 var ns = a - b; | 46 var ns = a - b; |
| 47 if (!isNaN(ns)) { | 47 if (!isNaN(ns)) { |
| 48 return ns; | 48 return ns; |
| 49 } | 49 } |
| 50 return a.localeCompare(b); | 50 return String(a).localeCompare(b); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 return swarming; | 53 return swarming; |
| 54 }(); | 54 }(); |
| OLD | NEW |