Tell us what’s happening:
Task has not passed, the reply is:
The peek method should return the top element of the stack
Your code so far
function Stack() {
var collection = [];
this.print = function() {
console.log(collection);
};
// Only change code below this line
this.push = collection.push;
this.pop = collection.pop;
this.peek = function() {
return collection[collection.length - 1];
}
this.isEmpty = function() {
return !collection.length
}
this.clear = function() {
collection = []
}
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
.
Challenge: Create a Stack Class
Link to the challenge: