Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Is a List Sorted?
- Write a program that checks if a list is already sorted. For a list to be
- sorted, the next element must NOT be smaller than the previous one.
- Input
- On the first line - you will receive a number N.
- On the next N lines, you will receive a list of numbers, separated by a comma
- Output
- There are N lines of output
- for each list you receive, print 'true' if sorted or 'false' otherwise.
- Constraints
- 1 <= N <= 10
- 1 <= list.length <= 20
- Input
- 3
- 1,2,3,4,5
- 1,2,8,9,9
- 1,2,2,3,2
- Output
- true
- true
- false
- */
- let input = ['3',
- '1,2,3,4,5',
- '1,2,8,9,9',
- '1,2,2,3,2'
- ];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- let arrNum = +gets();
- // console.log(arrNum);
- let arr = [];
- let result = '';
- for (let i = 1; i <= arrNum; i++) {
- arr = gets().split(',').map(Number);
- for (let j = 0; j <= arr.length - 2; j++) {
- if (arr[j] <= arr[j + 1]) {
- result = "true";
- } else {
- result = "false";
- break;
- }
- }
- console.log(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement