https://github.com/bradfloodx/stack-list
https://github.com/bradfloodx/stack-list
data-type nodejs stack
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bradfloodx/stack-list
- Owner: bradfloodx
- Created: 2017-08-02T00:12:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-09T23:07:10.000Z (over 8 years ago)
- Last Synced: 2025-08-04T03:29:25.477Z (6 months ago)
- Topics: data-type, nodejs, stack
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/stack-list
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# stack-list
A Node.js JavaScript implementation of the stack data type. Supporting both LIFO via `push()` and `pop()`, and FIFO via `push()` and `shift()`.
```bash
npm install stack-list
```
## Syntax
```js
new StackList(initialValue);
```
### Parameters
#### `initialValue`
An `Array` of values of any type to initially populate the stack list.
### Methods
#### `push()`
Push a new value to the top of the stack.
#### `pop()`
Take the top most value off the list and return it.
#### `shift()`
Take the bottom most value off the list and return it.
#### `peek()`
View the top most value on the list.
#### `inspect()`
View the bottom most value on the list.
#### `clear()`
Reset to an empty list.
### Properties
#### `size`
The number of elements in the list. Also available under alias property `length`.
## Examples
```js
const StackList = require('stack-list');
let list = new StackList(['Hey']); // Optional initial values
// Push
list.push('Mate');
// Get size
list.size; // 2
// Peek top value
list.peek(); // 'Mate'
// Pop top value
list.pop(); // 'Mate'
list.pop(); // 'Hey'
// Clear stack
list.clear();
```