* Sort with a comparer function * @param {SortFunction<T> | undefined} sortFn Sorting comparer function * @returns {void}
(sortFn)
| 86 | * @returns {void} |
| 87 | */ |
| 88 | sortWith(sortFn) { |
| 89 | if (this.size <= 1 || sortFn === this._lastActiveSortFn) { |
| 90 | // already sorted - nothing to do |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | /** @type {T[]} */ |
| 95 | const sortedArray = [...this].sort(sortFn); |
| 96 | super.clear(); |
| 97 | for (let i = 0; i < sortedArray.length; i += 1) { |
| 98 | super.add(sortedArray[i]); |
| 99 | } |
| 100 | this._lastActiveSortFn = sortFn; |
| 101 | this._invalidateCache(); |
| 102 | } |
| 103 | |
| 104 | sort() { |
| 105 | this.sortWith(this._sortFn); |
no test coverage detected