Reputation: 1
The error is in the first line, i have been staring at it forever and cant find the problem.
bfs() {
let result = []
let queue = []
queue.push(this.root)
while(queue.length) {
let currentNode = queue.shift()
result.push(currentNode.value)
if (currentNode.left) {
queue.push(currentNode.left)
}
if (currentNode.right) {
queue.push(currentNode.right)
}
}
return result
}
}
Upvotes: 0
Views: 109
Reputation: 81
bf(){
}
the above syntax is only valid within the scope of an ES6 class definition or an object literal.
for an object literal
const baz ={
name:"foo",
bar(){
//do anything
}
}
for an ES6 class
class baz {
bar(){
//do something
}
}
any use outside of the above will result in syntax error,
bar(); //a function call
the above code is used to call or invoke a function. To create or define a function, the syntax below are valid
function bar(){
//do something
}
const baz = ()=>{
//do something
}
const foo = function(){
//do something
}
(function(){
//do something
})() //immediately invoked function
Upvotes: 1