WIP
A possible implementation of a traversal
problems:
- returning an object instead of the index is idiosyncratic.
- currently accepts a string
- strict equality doesn't compare deeply nested properties with objects
- need to use prototypal inheritance to utilize the
hasOwnProperty
method in order to properly implement an object equality comparator
const balancedBinaryTreeSearch(val: String, tree: Array<Object>): Array<Object> {
let i = 0
// @todo implement a comparator
const strictEqualsConditional = (a,b) => a === b ? true : false
let result = []
const loop = () => {
for (; i < tree.length; i++) {
const compare() {
if(tree[i] === val) {
return {
index: i
}
} elseif(tree[2i+1] === val) {
return {
index: i,
node: "left"
}
} elseif(tree[2i+2] === val) {
return {
index: i,
node: "right"
}
} else {
return false
}
}
let res = compare()
if res result.push(res)
}
}
loop()
return result
}