Skip to content

Commit

Permalink
fix: Replace generator with a regular array as we generate it anyways…
Browse files Browse the repository at this point in the history
… at once
  • Loading branch information
marcbachmann committed Jun 5, 2020
1 parent 412baa3 commit d5c6425
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ module.exports = prepareSimpleTextSearch
function prepareSimpleTextSearch (collection, property) {
let cachedPrunedElements

function * prunedElements () {
let i = -1
cachedPrunedElements = []
function prunedElements () {
const elements = []
for (const elem of collection) {
i = i + 1
let val = elem
if (typeof property === 'string') val = val && val[property]
if (typeof val === 'object') val = JSON.stringify(val)
else if (typeof val !== 'string') continue
val = { pruned: clean(val), elem }
cachedPrunedElements[i] = val
yield val
elements.push(val)
}
cachedPrunedElements = elements
return cachedPrunedElements
}

return function simpleTextSearch (q) {
Expand Down

0 comments on commit d5c6425

Please sign in to comment.