Alpha sort for search
This commit is contained in:
parent
2bba8fb6f4
commit
932b93b9c7
1 changed files with 16 additions and 1 deletions
|
@ -174,7 +174,22 @@ class Vegetables {
|
|||
callback(new Error('No vegetable found'), 204)
|
||||
return false
|
||||
}
|
||||
callback(null, items)
|
||||
|
||||
const _items = items.rows.toJSON()
|
||||
let vegetables = []
|
||||
|
||||
for (let j = 0; j < _items.length; j += 1) {
|
||||
let k = 0
|
||||
for (k = 0; k < vegetables.length; k += 1) {
|
||||
if (_items[j].name.localeCompare(vegetables[k].name) === -1) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
vegetables.splice(k, 0, _items[j])
|
||||
}
|
||||
|
||||
callback(null, { count: vegetables.length, rows: vegetables })
|
||||
})
|
||||
.catch((e) => {
|
||||
callback(e, null)
|
||||
|
|
Loading…
Reference in a new issue