I am trying to solve this in Nodejs. But not sure if its right or wrong. No feedback given ffrom the compiler.
function isSorted(array){
if(array.length === 1){
return true;
}
const isPrevSorted = isSorted(array.slice(1));
if(isPrevSorted && array[0] < array[1]){
return true;
}
return false;
}
function isSortedArray(n, nums){
const array = nums.split(’ ').map(n => parseInt(n));
console.log(typeof array[0]);
const result = isSorted(array);
console.log(result);
}
isSortedArray(3, “1 2 3 4 5”);