UNPKG

kamranqadri

Version:

<center><img width="550" style="margin-bottom: 20px;" src="img/card.png" /></center>

21 lines (18 loc) 570 B
// Given an array of integers, write a function that will return a boolean that determines if the array is sorted, lowest to highest. const isSorted = (array) => { let result = true; array.forEach((item, i) => { if (array[i - 1] > item) { result = false; } }) return result; }; console.log(isSorted([-1, 0, 1])) console.log(isSorted([-1, 3, 10, 10])) console.log(isSorted([1, 1, 1])) console.log(isSorted([0, -1])) console.log(isSorted([0])) console.log(isSorted([-1, -3])) console.log(isSorted([])) console.log(isSorted([-1, 0, 1, 10, 9, 10]))