Alpha sort for search

This commit is contained in:
dbroqua 2019-04-11 19:20:24 +02:00
parent 2bba8fb6f4
commit 932b93b9c7

View File

@ -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)