You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code is working fine, but currently, it is only checking whether the passed array is sorted in ascending order, should we want to check whether the array is sorted in descending order then it will not be of much help.
Examples
Currently, the function checks whether an array is sorted, taking a single parameter: the array to evaluate. To enhance its functionality, I propose adding a second parameter that specifies the order to check for sorting.
The second parameter should be a string such as:
asc to check whether the array is sorted in ascending order.
desc to check whether the array is sorted in descending order.
So, your idea is that the function should now be called with two parameters, the array to be sorted and and a callback function which will be the comparator?
So, your idea is that the function should now be called with two parameters, the array to be sorted and and a callback function which will be the comparator?
Yes (your example should have a different comparator in the second line btw). But the comparator should default to something sensible (such that it checks whether the array is sorted ascendingly by default, just like Array.sort sorts ascendingly by default).
Motivation
I have been looking at the code for checking whether an array is sorted and this is the current implementation:
The code is working fine, but currently, it is only checking whether the passed array is sorted in ascending order, should we want to check whether the array is sorted in descending order then it will not be of much help.
Examples
Currently, the function checks whether an array is sorted, taking a single parameter: the array to evaluate. To enhance its functionality, I propose adding a second parameter that specifies the order to check for sorting.
The second parameter should be a string such as:
asc
to check whether the array is sorted in ascending order.desc
to check whether the array is sorted in descending order.Here are some example:
Possible workarounds
No response
The text was updated successfully, but these errors were encountered: