how to check string array is sorted or not in typescript 1

how to check string array is sorted or not in typescript

let sorts = +gets(); // 3
let list = [];

for (let i = 0; i < sorts; i++) {
    list[i] = gets().split(',').map(Number); // The Array will be: [ [ 1, 2, 3, 4, 5 ], [ 1, 2, 8, 9, 9 ], [ 1, 2, 2, 3, 2 ] ]
}

for (let i = 0; i < list[i][i].length; i++){
    if (list[i][i] < list[i][i +1]) {
        print('true');
    } else {
        print('false');
    }
}

Here is what the above code is Doing:
1. We're getting the number of arrays we want to sort.
2. We're creating an empty array.
3. We're getting the arrays we want to sort.
4. We're comparing the first element of the first array with the second element of the first array.
5. If the first element is smaller than the second element, we print true.
6. If the first element is bigger than the second element, we print false.

The problem is that we're comparing the first element of the first array with the second element of the first array.
We need to compare the first element of the first array with the first element of the second array.

Similar Posts