function bubbleSort(values: number[]): number[] { let end = values.length - 1 values = values.slice(0) let swapped do { swapped = false while (end > 0) { let left = 0 let right = left + 1 while (right <= end) { let leftValue = values[left] let rightValue = values[right] if (leftValue > rightValue) { values[left] = rightValue values[right] = leftValue } left++ right++ swapped = true } end-- } } while (swapped) return values }