Skip to content

Instantly share code, notes, and snippets.

@kaisinli kaisinli/arrayception.js
Last active Aug 22, 2018

Embed
What would you like to do?
arrayception
function arrayception(arr) {
let str = JSON.stringify(arr);
let openCounter = 0;
let maxDepth = 0;
for (let i = 0; i < str.length; i++) {
if (str[i] === '[') {
openCounter++;
} else if (str[i] === ']') {
openCounter--
} else if (str[i] !== ']' && str[i] !== '[') {
if (openCounter > maxDepth) maxDepth = openCounter
}
}
return maxDepth;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.