Испытание "Рекорды по прыжкам в длину" : Шейкер сортировка!

let qualificationDistance = 200;
let attempts = [120, 150, 160, 201, 203, 180, 202];
let qualified = false;
let averageBest = 0;

let swapEL = function(arr, i) {
let buff = arr[i];
arr[i] = arr[i-1];
arr[i-1] = buff;
}

let shakerSort = function(arr) {
let leftMark = 1;
let rightMark = arr.length - 1;
while(leftMark <= rightMark) {
for(let i = rightMark;i >= leftMark; i–) {
if(arr[i-1] > arr[i]) swapEL(arr, i);
}
leftMark++;

for(let i = leftMark; i <= rightMark; i++) {
if(arr[i-1]>arr[i]) swapEL(arr,i);
}
rightMark–;
}
}

shakerSort(attempts);

averageBest = (attempts[attempts.length - 1] + attempts[attempts.length - 2] + attempts[attempts.length - 3]) / 3;

if(averageBest > qualificationDistance) {
qualified = true;
}