From 0932891b20221a8382306bbc82fc8d437c5b6c50 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Fri, 26 Jun 2020 15:52:53 +0200 Subject: [PATCH] do not modify original object on recursive filter --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 12b29e3..64e691d 100644 --- a/index.js +++ b/index.js @@ -81,11 +81,12 @@ function is_nil (obj) { /** * filter nested objects * - * @param {Array} data + * @param {Array} input * @param {Array<{field: string, filter: RegExp}>} filters * @returns {Array} filtered data */ -function recursive_filter (data, filters, children_key = 'children') { +function recursive_filter (input, filters, children_key = 'children') { + const data = copy_object (input); const filtered = []; for (const e of data) { let match = true;