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 TraverseHybrid(bookarray, resultArray = [], currentObj = {}){ | |
//Safe case when bookarray is not an array. | |
if (!Array.isArray(bookarray)) return resultArray; | |
//Safe case when bookarray is empty. | |
if (bookarray.length <= 0) return resultArray.push(currentObj); | |
let resultObj = {}; | |
let data = {}; |
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])) |
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 PowTCOExample(val, exp, result = 1){ | |
//Safe case to catch all possible errors | |
if(val == 0 || typeof val != 'number' | |
|| typeof exp != 'number') return 0; | |
//First base case. Avoid recursivity when | |
//power is 0. | |
if(exp === 0) return 1; | |
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
let isObjectEmpty = (obj) => { | |
return Object.keys(obj).length === 0; | |
}; | |
let isPrimitive = (element) => { | |
return (typeof element === 'object') ? element === null : typeof element !== 'function'; | |
}; | |
function TraverseRecursiveArray (myarray, pos, obj){ |
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 PowExample(val, exp){ | |
//Safe case to catch all possible errors | |
if(val == 0 || typeof val != 'number' | |
|| typeof exp != 'number') return 0; | |
//First base case. Avoid recursivity when | |
//power is 0. | |
if(exp === 0) return 1; | |