Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 606 Bytes

stack.md

File metadata and controls

29 lines (22 loc) · 606 Bytes

Stack

LIFO dog 🐕, Last In First Out. The addition of new items or removal of existing items takes place at the same end.

    function Stack() {
        let items = [];

        this.push = function(element) {
            items.push(element);
        }

        this.pop = function() {
            return items.pop();
        }

        this.clear = function() {
            items = [];
        }

        this.peek = function() {
            return items[items.length - 1];
        }

        this.isEmpty = function() {
            return items.length === 0;
        }
    }