BigW Consortium Gitlab

Commit 521c0f5f by Alfredo Sumaran

Reduce the use of loops

parent a477d604
......@@ -97,25 +97,20 @@ class @SearchAutocomplete
}, (response) ->
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
for groupName in groupNames
for suggestion in response
# Add group header before list each group
if lastCategory isnt suggestion.category
data.push
header: suggestion.category
lastCategory = suggestion.category
data.push
header: groupName
text: suggestion.label
url: suggestion.url
# List group
for item in groups[groupName]
data.push
text: item.label
url: item.url
callback(data)
).always ->
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