From d5c642595bef614d7816d0403456422eaf0d25a0 Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Fri, 5 Jun 2020 18:54:25 +0200 Subject: [PATCH] fix: Replace generator with a regular array as we generate it anyways at once --- index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 9d2772e..a01a82a 100644 --- a/index.js +++ b/index.js @@ -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) {