Commit 521c0f5f authored by Alfredo Sumaran's avatar Alfredo Sumaran

Reduce the use of loops

parent a477d604
...@@ -97,25 +97,20 @@ class @SearchAutocomplete ...@@ -97,25 +97,20 @@ class @SearchAutocomplete
}, (response) -> }, (response) ->
data = [] data = []
# Save groups ordering according to server response
groupNames = _.unique(_.pluck(response, 'category'))
# Group results by category name
groups = _.groupBy response, (item) ->
item.category
# List results # List results
for groupName in groupNames for suggestion in response
# Add group header before list each group # Add group header before list each group
if lastCategory isnt suggestion.category
data.push data.push
header: groupName header: suggestion.category
lastCategory = suggestion.category
# List group
for item in groups[groupName]
data.push data.push
text: item.label text: suggestion.label
url: item.url url: suggestion.url
callback(data) callback(data)
).always -> ).always ->
loading = false loading = false
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment