All Tracks/lab implement a stack/
Đang tải...
Hướng dẫn thử thách
1 / 1

Implement a Stack

In this lab, you will implement a stack data structure using functions. A stack is a Last-In-First-Out (LIFO) data structure where elements are added and removed from the top. **Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. **User Stories:** 1. You should have an `initStack` function that returns an object with a `collection` property set to an empty array. 1. You should have a `push` function that adds an element to the top of the stack. 1. You should have a `pop` function that removes and returns the top element of the stack, or `undefined` if there isn't one. 1. You should have a `peek` function that returns the top element of the stack without removing it, or `undefined` if there isn't one. 1. You should have an `isEmpty` function that returns `true` if the stack contains no elements, and `false` otherwise. 1. You should have a `clear` function that removes all elements from the stack. **Note:** Most tests depend on the `initStack` and `push` functions. Implement them first, as tests for `pop`, `peek`, `isEmpty`, and `clear` require adding elements to the stack.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.js
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵
Test Output
Thử thách này không có bài test tự động. Hãy quan sát kết quả trực tiếp ở khung Preview.