In javascript (underscore) , how do I test whether a list of numbers is already sorted or not?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I found this very helpful link.
A simple solution would be to simply iterate over the list, examining whether each element is smaller than its next neighbor:
I found solution in pure js with every:
You can use
_.every
to check whether all elements are in order:A simple es6 code: