Try to solve Learn Data Structures: Create a Stack Class | freeCodeCamp.org
I know the answer can be simple as return collection.pop()
, but I want to try alternative method. cl=collection.length
I don’t know why the pop method can’t pass the test
this.pop = function(){
if (cl===0){
return undefined
}else if(cl > 0){
let popelement = collection[cl-1]
collection[cl-1] = undefined
return popelement
}
}