Created
November 17, 2018 22:50
-
-
Save SergioR82/c0c99e85f997b623eb34899c4cfd0192 to your computer and use it in GitHub Desktop.
Traverse books with TCO implementation
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
function TraverseWithTOC([obj,...subarray], resultArray = [], currentObj = {}){ | |
if (obj === undefined) return resultArray; | |
if (typeof obj === 'object' && !(isObjectEmpty(obj))){ | |
let hasPropArray = false; | |
let resultObj = {}; | |
for (let property in obj) { | |
if (obj.hasOwnProperty(property)) { | |
if (isPrimitive(obj[property])) | |
resultObj[property] = obj[property]; | |
else | |
if (Array.isArray(obj[property])){ | |
hasPropArray = true; | |
TraverseWithTOC(obj[property], resultArray, resultObj); | |
}; | |
}; | |
}; | |
if (!hasPropArray) | |
resultArray.push(Object.assign({},currentObj,resultObj)); | |
}; | |
return TraverseWithTOC(subarray,resultArray, currentObj); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment