Рекорды по прыжкам в длину 30/30 (пример выполнения))

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

//sort
for (var i = 0; i <= attempts.length - 2; i++) {
var minValue = attempts[i];

for (var j = i + 1; j <= attempts.length - 1; j++) {
if (attempts[j] < minValue) {
minValue = attempts[j];
var swap = attempts[i];
attempts[i] = minValue;
attempts[j] = swap;
}
}
}

// massiv
console.log(attempts);
// summ 3 records
for ( i = attempts.length-1; i>=attempts.length-3;i–){
averageBest +=attempts[i];
console.log(attempts[i]);
}
// find AVG
averageBest = averageBest/3;

//test
if (averageBest>qualificationDistance){
qualified = true;}
else{
qualified = false;}

Мой вариант

for (var i = 0; i < attempts.length - 1 ; i++) {
  var max = attempts[i];  
  for (var j = i + 1; j <= attempts.length - 1; j++) {
    if (attempts[j] > max) {
      max = attempts[j];
      var swap = attempts[i];
      attempts[i] = max;
      attempts[j] = swap;
      }
    }
  }

averageBest = (attempts[0] + attempts[1] + attempts[2])/3;
if (averageBest > qualificationDistance) {
  qualified = true;
  } else {
    qualified = false;
    }
1 Симпатия

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

// Сортируем массив
for (var i = 0; i <= attempts.length - 2; i++) {
var minValue = attempts[i];

for (var j = i + 1; j <= attempts.length - 1; j++) {
if (attempts[j] < minValue) {
minValue = attempts[j];
var swap = attempts[i];
attempts[i] = minValue;
attempts[j] = swap;
}
}
}
console.log(attempts);

// Суммируем посещаемость
var totalUsers = 0;
var totalPoint =0;
var massivLength = attempts.length - 3;
for (massivLength; massivLength <= attempts.length - 1; massivLength++) {
totalUsers += attempts[massivLength];
totalPoint ++;
}
console.log(totalPoint);
console.log(totalUsers);

// Рассчитываем среднее значение посещаемости
var averageBest = totalUsers / totalPoint;
console.log('Средняя длина прыжка: ’ + averageBest);

if (averageBest > qualificationDistance) {
qualified = true;
console.log(‘Молодец, ты прошёл квалификацию!’);
} else {
console.log(‘Результаты так себе. Нужно поднапрячься!’);
}

Мой вариант:

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

/* Сортируем массив и расставляем его элементы от большего к меньшему */

attempts = attempts.sort().reverse();

/* Выполняем проверку на кол-во попыток */

if (attempts.length > 3) { // Если попыток больше 3, то
for (let i = 0; i < attempts.length; i++) { // проходимся через массив до 4-го элемента
if (i < 3) { // и добавляем значение прыжка к среднему
averageBest += attempts[i]; // (деление оставляем на потом)
}
}
averageBest /= 3; // узнаем среднее
qualified = averageBest > qualificationDistance; // Выполняем проверку

} else {
for (let i = 0; i < attempts.length; i++) {
averageBest += attempts[i];
}
averageBest /= 3;
qualified = averageBest > qualificationDistance;
}

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

for (let i = 0; i <= attempts.length - 2; i++) {
  let maxValue = attempts[i];

  for (let j = i + 1; j <= attempts.length - 1; j++) {
    if (attempts[j] > maxValue) {
      maxValue = attempts[j];
      let swap = attempts[i];
      attempts[i] = maxValue;
      attempts[j] = swap;
    }
  }
}

averageBest = (attempts[0] + attempts[1] + attempts[2]) / 3;
if (averageBest>qualificationDistance) {
  qualified = true; 
  } else {
   qualified = false;
   }
const qualificationDistance = 200;
const attempts = [120, 150, 160, 201, 203, 180, 202];
let qualified = false;
let averageBest = 0;

const sorted = attempts.sort((a,b) => b - a);
const best = [sorted[0], sorted[1], sorted[2]];
averageBest = best.reduce((a, b) => (a + b)) / best.length;
(averageBest > qualificationDistance) ? qualified = true : qualified;