From e58b397b47b0f7e31e82b36c2fc96b8605a31872 Mon Sep 17 00:00:00 2001 From: lvzhenbang Date: Mon, 25 Dec 2017 13:41:45 +0800 Subject: [PATCH 1/3] Fix the same format as other methods I think the consistency of the format is good and necessary. --- snippets/cleanObj.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/snippets/cleanObj.md b/snippets/cleanObj.md index f2a915719..2b74d6743 100644 --- a/snippets/cleanObj.md +++ b/snippets/cleanObj.md @@ -7,17 +7,16 @@ Also if you give it a special key (`childIndicator`) it will search deeply insid ```js const cleanObj = (obj, keysToKeep = [], childIndicator) => { - Object.keys(obj).forEach(key => { + return Object.keys(obj).forEach(key => { if (key === childIndicator) { cleanObj(obj[key], keysToKeep, childIndicator); } else if (!keysToKeep.includes(key)) { delete obj[key]; } - }) +  }), obj } /* const testObj = {a: 1, b: 2, children: {a: 1, b: 2}} - cleanObj(testObj, ["a"],"children") - console.log(testObj)// { a: 1, children : { a: 1}} + cleanObj(testObj, ["a"],"children") // { a: 1, children : { a: 1}} */ ``` From 52f7a7dee864dd222e2544dcd4860d8e3c143dd0 Mon Sep 17 00:00:00 2001 From: Soorena Date: Tue, 26 Dec 2017 14:29:51 +0330 Subject: [PATCH 2/3] Update cleanObj.md I changed comma operator because it confuses the reader. --- snippets/cleanObj.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snippets/cleanObj.md b/snippets/cleanObj.md index 2b74d6743..099b607ab 100644 --- a/snippets/cleanObj.md +++ b/snippets/cleanObj.md @@ -7,13 +7,14 @@ Also if you give it a special key (`childIndicator`) it will search deeply insid ```js const cleanObj = (obj, keysToKeep = [], childIndicator) => { - return Object.keys(obj).forEach(key => { + Object.keys(obj).forEach(key => { if (key === childIndicator) { cleanObj(obj[key], keysToKeep, childIndicator); } else if (!keysToKeep.includes(key)) { delete obj[key]; } -  }), obj +  }) + return obj } /* const testObj = {a: 1, b: 2, children: {a: 1, b: 2}} From 3693c7e82cc35d4981df4728dfbd14b449066362 Mon Sep 17 00:00:00 2001 From: David Wu Date: Tue, 26 Dec 2017 14:18:13 +0100 Subject: [PATCH 3/3] Update cleanObj.md --- snippets/cleanObj.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/cleanObj.md b/snippets/cleanObj.md index 099b607ab..82cfe4441 100644 --- a/snippets/cleanObj.md +++ b/snippets/cleanObj.md @@ -13,8 +13,8 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => { } else if (!keysToKeep.includes(key)) { delete obj[key]; } -  }) - return obj +  }); + return obj; } /* const testObj = {a: 1, b: 2, children: {a: 1, b: 2}}