Advertisement
3vo

Problem 1. Exchange If Greater

3vo
Oct 25th, 2022
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Write an if-statement that takes two double variables a and b and exchanges their values if the first one is greater than the second one.
  2. // As a result print the values a and b, separated by a space.
  3. //     Examples:
  4. // a    b   result
  5. // 5    2   2 5
  6. // 3    4   3 4
  7. // 5.5  4.5 4.5 5.5
  8.  
  9. let input = ['5.5', '4.5'];
  10. let print = this.print || console.log;
  11. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  12. // get two values a and b
  13. let a = +gets();
  14. let b = +gets();
  15. //exchanges their values if the first one is greater than the second one and
  16. //print separated by a space
  17. if (a > b) {
  18.     console.log(`${b} ${a}`);
  19. } else {
  20.     console.log(`${a} ${b}`);
  21. }
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement