Skip to content

Instantly share code, notes, and snippets.

@JoviDeCroock
Last active October 14, 2019 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoviDeCroock/7f7275dff902fa23b46d9a44f059789c to your computer and use it in GitHub Desktop.
Save JoviDeCroock/7f7275dff902fa23b46d9a44f059789c to your computer and use it in GitHub Desktop.
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 }
}, {});
}
@Pruxis
Copy link

Pruxis commented Oct 14, 2019

copy van je obj, aj aj aj slooooooow!!!!! haha thanks tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment