Lor*_*ard 9 javascript underscore.js
在javascript(下划线)中,如何测试数字列表是否已经排序?
pim*_*vdb 17
您可以_.every用来检查所有元素是否按顺序排列:
_.every(arr, function(value, index, array) {
// either it is the first element, or otherwise this element should
// not be smaller than the previous element.
// spec requires string conversion
return index === 0 || String(array[index - 1]) <= String(value);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8705 次 |
| 最近记录: |