Advertisement
3vo

Problem 4. Smaller, greater or equal?

3vo
Nov 2nd, 2022
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Problem 4. Smaller, greater or equal?
  2. // Write a program that reads from the console a sequence of n integer numbers and
  3. // returns these numbers on a single line with the correct sign (<, > or =) between the numbers.
  4. //Examples:
  5. // input    output
  6. // 3
  7. // 2
  8. // 5
  9. // 1       2<5>1
  10. //
  11. // input   output
  12. // 4
  13. // -1
  14. // 4     -1<4=4=4
  15. // 4
  16. // 4
  17.  
  18. let input = ['3', '2', '5', '1'];
  19.  
  20. let print = this.print || console.log;
  21. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  22.  
  23. let num = +gets(); //gets the number of inputs
  24. let allNums = '';
  25. let array = [];
  26. let result = '';
  27.  
  28. //get all inputs and keep it in array
  29. for (let i = 0; i < num; i++) {
  30.     allNums = +gets();
  31.     array.push(allNums);
  32. }
  33. // check the numbers in the array and put the signs between
  34. for (let j = 0; j < array.length; j++) {
  35.     if (array[j] > array[j + 1]) {
  36.         result += `${array[j]} > `;
  37.     }
  38.     if (array[j] < array[j + 1]) {
  39.         result += `${array[j]} < `;
  40.     }
  41.     if (array[j] === array[j + 1]) {
  42.         result += `${array[j]} = `;
  43.     }
  44.     if (j === array.length - 1) {
  45.         result += `${array[j]}`;
  46.     }
  47. }
  48.  
  49.  
  50. console.log(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement