From 8eb807714c0b9546918ef06363615d1d655e2768 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Mon, 29 Jun 2020 11:33:33 +0200 Subject: [PATCH] optimize recursive filter --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 39e7fe1..c78212d 100644 --- a/index.js +++ b/index.js @@ -86,9 +86,11 @@ function is_nil (obj) { * @returns {Array} filtered data */ function recursive_filter (input, filters, children_key = 'children') { - const data = copy_object (input); + const data = [ ...input ]; const filtered = []; - for (const e of data) { + for (let i = 0; i < data.length; i++) { + const e = { ...data[i] }; + data[i] = e; let match = true; for (const filter of filters) { let search_str = '';