Advertisement
Spocoman

07. Min Number

Dec 27th, 2021 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function minNumber(input) {
  2.     let index = 0;
  3.     let min = Number.MAX_VALUE;
  4.     while (input[index] !== "Stop"){
  5.         let num = Number(input[index]);
  6.         if (min > num){
  7.             min = num;
  8.         }
  9.         index++;
  10.     }
  11.     console.log(min);
  12. }
  13.  
  14. Решение с фор цикъл:
  15.  
  16. function minNumber(input) {
  17.  
  18.     let min = Number.MAX_VALUE;
  19.     for(let i = 0; i <= Number.MAX_VALUE; i++) {
  20.         if (input[i] === "Stop"){
  21.             break;
  22.         } else if (min > Number(input[i])) {
  23.             min = Number(input[i]);
  24.         }
  25.     }
  26.     console.log(min);
  27. }
  28.  
  29. Фундаменталс решение:
  30.  
  31. function maxNumber(input) {
  32.     console.log(Math.min(...input.slice(0, -1).map(Number)));
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement