I recently developed a function that aims to verify if an array of numbers is sorted:
const checkIfSorted = (numbers: number[]) => {
return numbers === numbers.sort((a, b) => a - b);
};
checkIfSorted([4, 2, 8, 7, 3, 10, 1, 5, 9, 6]); // This currently returns `true`
The problem lies in the fact that the function always returns true
, which indicates it's not working correctly. How could I adjust this function to provide accurate results?
Here are the tools and versions I am utilizing:
- TypeScript v4.1.2
- ts-node v9.0.0
- Node.js v14.15.1