Advertisement
3vo

Problem 6. The Biggest of Five Numbers

3vo
Oct 25th, 2022
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.74 KB | Source Code | 0 0
  1. //Problem 6. The Biggest of Five Numbers
  2. //
  3. //Write a program that finds the biggest of five numbers. Think about a way to do it more efficient.
  4.  
  5. //Examples:
  6. //  a    b    c   d    e     biggest
  7. //  5    2    2   4    1     5
  8. // -2   -22   1   0    0     1
  9. // -2    4    3   2    0     4
  10. //  0   -2.5  0   5    5     5
  11. // -3   -0.5 -1.1 -2  -0.1  -0.1
  12. let input = ['5', '2', '2','4','1'];
  13. let print = this.print || console.log;
  14. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  15. //Get all 5 numbers
  16. let n1 = Number(gets());
  17. let n2 = Number(gets());
  18. let n3 = Number(gets());
  19. let n4 = Number(gets());
  20. let n5 = Number(gets());
  21. //Finds the biggest of five numbers
  22. let maxNum = Math.max(n1, n2, n3, n4, n5);
  23.  
  24. console.log(maxNum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement