Chore/remove is object

This commit is contained in:
Sofiya Tepikin
2022-07-31 18:23:17 +00:00
parent 7b100d2dfc
commit 3015628821
4 changed files with 49 additions and 13 deletions
+12
View File
@@ -0,0 +1,12 @@
const isObject = (obj) => obj === Object(obj)
export default function replaceWithNullIfAllPropertiesAreNull(obj) {
Object.keys(obj).forEach((key) => {
if (!isObject(obj[key])) return
if (Object.values(obj[key]).every((val) => val === null)) {
obj[key] = null
return
}
replaceWithNullIfAllPropertiesAreNull(obj[key])
})
}