vladovip

Numbers_MidExamPreparation_JS Fund

Feb 21st, 2022 (edited)
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numbers(input) {
  2.   let arrOfNums = input.split(" ").map(Number);
  3.   let averageSum = 0;
  4.   for (let index = 0; index < arrOfNums.length; index++) {
  5.     averageSum += parseInt(arrOfNums[index]) / arrOfNums.length;
  6.   }
  7.  
  8.   let tempArr = arrOfNums.filter((x) => x > averageSum);
  9.   let sortedArrDescendinfOrder = tempArr.sort((a, b) => b - a);
  10.  
  11.   if (sortedArrDescendinfOrder.length <= 0) {
  12.     console.log("No");
  13.   } else {
  14.     let resultArr = sortedArrDescendinfOrder.splice(0, 5);
  15.     console.log(resultArr.join(" "));
  16.   }
  17.  
  18. }
  19.  
  20. numbers("10 20 30 40 50");
  21. numbers("5 2 3 4 -10 30 40 50 20 50 60 60 51");
  22. numbers("1");
  23. numbers("-1 -2 -3 -4 -5 -6");
  24.  
Add Comment
Please, Sign In to add comment