Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem 4. Smaller, greater or equal?
- // Write a program that reads from the console a sequence of n integer numbers and
- // returns these numbers on a single line with the correct sign (<, > or =) between the numbers.
- //Examples:
- // input output
- // 3
- // 2
- // 5
- // 1 2<5>1
- //
- // input output
- // 4
- // -1
- // 4 -1<4=4=4
- // 4
- // 4
- let input = ['3', '2', '5', '1'];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- let num = +gets(); //gets the number of inputs
- let allNums = '';
- let array = [];
- let result = '';
- //get all inputs and keep it in array
- for (let i = 0; i < num; i++) {
- allNums = +gets();
- array.push(allNums);
- }
- // check the numbers in the array and put the signs between
- for (let j = 0; j < array.length; j++) {
- if (array[j] > array[j + 1]) {
- result += `${array[j]} > `;
- }
- if (array[j] < array[j + 1]) {
- result += `${array[j]} < `;
- }
- if (array[j] === array[j + 1]) {
- result += `${array[j]} = `;
- }
- if (j === array.length - 1) {
- result += `${array[j]}`;
- }
- }
- console.log(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement