added let-statment

This commit is contained in:
Christian Bender
2018-03-31 00:01:22 +02:00
parent b9d749acd2
commit 969902a73d

View File

@ -7,9 +7,9 @@
*/ */
Array.prototype.heapify = function (index, heapSize) { Array.prototype.heapify = function (index, heapSize) {
var largest = index; let largest = index;
var leftIndex = 2 * index + 1; let leftIndex = 2 * index + 1;
var rightIndex = 2 * index + 2; let rightIndex = 2 * index + 2;
if (leftIndex < heapSize && this[leftIndex] > this[largest]) { if (leftIndex < heapSize && this[leftIndex] > this[largest]) {
largest = leftIndex; largest = leftIndex;
@ -20,7 +20,7 @@ Array.prototype.heapify = function (index, heapSize) {
} }
if (largest !== index) { if (largest !== index) {
var temp = this[largest]; let temp = this[largest];
this[largest] = this[index]; this[largest] = this[index];
this[index] = temp; this[index] = temp;
@ -35,13 +35,13 @@ Array.prototype.heapify = function (index, heapSize) {
*/ */
function heapSort(items) { function heapSort(items) {
var length = items.length; let length = items.length;
for (var i = Math.floor(items.length / 2) - 1; i > -1; i--) { for (let i = Math.floor(length / 2) - 1; i > -1; i--) {
items.heapify(i, length); items.heapify(i, length);
} }
for (var j = length -1; j > 0; j--) { for (let j = length -1; j > 0; j--) {
var tmp = items[0]; let tmp = items[0];
items[0] = items[j]; items[0] = items[j];
items[j] = tmp; items[j] = tmp;
items.heapify(0, j); items.heapify(0, j);