Test name | Executions per second |
---|---|
_.orderBy | 22169.0 Ops/sec |
Array.sort | 342042.1 Ops/sec |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var generateText = function(){
return Math.random().toString(36).substring(2, 4);
}
var arr = []
for(i=0; i<100; i++){
const obj = {}
obj.id = i;
obj.text = generateText()
arr.push(obj)
}
_.orderBy(arr, ['text', 'id'], ['desc', 'asc'])
arr.sort((a, b) => (a.text < b.text) ? 1 : (a.text === b.text) ? ((a.id > b.id) ? 1 : -1) : -1 )