Last active
October 14, 2019 17:19
-
-
Save JoviDeCroock/7f7275dff902fa23b46d9a44f059789c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const seen = [] | |
function traverseObject(obj) { | |
Object.keys(obj).reduce((acc, key) => { | |
const value = obj[key]; | |
if (typeof value !== 'object) return { ...acc, [key]: value }; | |
if (Array.isArray(value) { | |
return { ...acc, [key]: value.map(traverseObject) } | |
} | |
if (seen.indexOf(value) !== -1) { | |
return { ...acc, [key]: 'cycle' } | |
} | |
const seenIndex = seen.push(node) - 1; | |
const objValue = traverseObject(value) | |
seen.splice(seenIndex, 1); | |
return { ...acc, [key]: objValue } | |
}, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy van je obj, aj aj aj slooooooow!!!!! haha thanks tho