1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52# stack
Javascript implementation of [Stack data structure](<https://en.wikipedia.org/wiki/Stack_(abstract_data_type)>), using [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
### Getting Started
---
Install in your project with,
```
npm install @iamlizu/stack
```
Usage example,
```
const Stack = require("@iamlizu/stack")
// Create new instance
const stack1 = new Stack();
stack1.push(10);
console.log(stack1.getBuffer()) // [ 10 ]
```
### Available Methods
---
| Method | Description |
| ------------- | -------------------------------------------------- |
| getBuffer | returns a shallow copy of the Stack array |
| isEmpty | return `true` if empty |
| push | adds item to the Stack |
| pop | remove item from the Stack |
| peek | returns the top item from Stack without popping it |
| size | returns the length of the Stack |
| clear | resets the Stack to empty |
| access(index) | returns the item on `index` from Stack |
| search(item) | returns the `index` of given `item` in the Stack |
### Contributing
---
You are very much appreciated to add new functionalities to this module. Please add all the required test cases for the functionality.
You may create a pull request and wait to get reviewed, merged.
๐ Happy coding!