Skip to content

Commit 51ae09c

Browse files
authored
Merge pull request #10 from datastructures-js/development
v2.0.4
2 parents 3ec3223 + b991f7d commit 51ae09c

4 files changed

Lines changed: 33 additions & 35 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.0.4] - 2020-12-26
10+
### Fixed
11+
- jsdoc
12+
- readme
13+
914
## [2.0.3] - 2020-04-03
1015
### Fixed
1116
- .npmignore

README.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ A wrapper around javascript array push/pop with a standard stack interface.
88

99
# Table of Contents
1010
* [Install](#install)
11+
* [require](#require)
12+
* [import](#import)
1113
* [API](#api)
12-
* [require](#require)
13-
* [import](#import)
1414
* [Construction](#construction)
1515
* [.push(element)](#pushelement)
1616
* [.peek()](#peek)
@@ -29,25 +29,20 @@ A wrapper around javascript array push/pop with a standard stack interface.
2929
npm install --save @datastructures-js/stack
3030
```
3131

32-
## API
33-
3432
### require
35-
3633
```js
3734
const Stack = require('@datastructures-js/stack');
3835
```
3936

4037
### import
41-
4238
```js
4339
import Stack from '@datastructures-js/stack';
4440
```
41+
## API
4542

4643
### Construction
4744

48-
#### using "new Stack(array)"
49-
50-
##### Example
45+
#### using "new"
5146

5247
```js
5348
// empty stack
@@ -57,9 +52,7 @@ const stack = new Stack();
5752
const stack = new Stack([10, 3, 8, 40, 1]);
5853
```
5954

60-
#### using "Stack.fromArray(array)"
61-
62-
##### Example
55+
#### using ".fromArray"
6356

6457
```js
6558
// empty stack
@@ -69,8 +62,8 @@ const stack = Stack.fromArray([]);
6962
const list = [10, 3, 8, 40, 1];
7063
const stack = Stack.fromArray(list);
7164

72-
// If the list should not be mutated, simply construct the stack from a copy of it.
73-
const stack = Stack.fromArray(list.slice(0));
65+
// If the list should not be mutated, use a copy of it.
66+
const stack = Stack.fromArray(list.slice());
7467
```
7568

7669
### .push(element)
@@ -79,7 +72,7 @@ push an element to the top of the stack.
7972
<table>
8073
<tr><th align="center" colspan="2">params</th></tr>
8174
<tr><td><b>name</b></td><td><b>type</b></td></tr>
82-
<tr><td>element</td><td>object</td></tr>
75+
<tr><td>element</td><td>any</td></tr>
8376
</table>
8477

8578
<table>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@datastructures-js/stack",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "stack implementation in javascript",
55
"main": "index.js",
66
"scripts": {

src/stack.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
/**
2-
* @datastructures-js/stack
3-
* @copyright 2020 Eyas Ranjous <eyas.ranjous@gmail.com>
42
* @license MIT
5-
*/
6-
7-
/**
8-
* @class Stack
9-
* implements LIFO principle.
3+
* @copyright 2020 Eyas Ranjous <eyas.ranjous@gmail.com>
4+
*
5+
* @class
106
*/
117
class Stack {
8+
/**
9+
* Creates a stack.
10+
* @param {array} [elements]
11+
*/
1212
constructor(elements) {
1313
this._elements = Array.isArray(elements) ? elements : [];
1414
}
1515

1616
/**
17+
* Checks if the stack is empty.
1718
* @public
18-
* checks if the stack is empty
1919
* @returns {boolean}
2020
*/
2121
isEmpty() {
2222
return this._elements.length === 0;
2323
}
2424

2525
/**
26+
* Returns the number of elements in the stack.
2627
* @public
27-
* returns the number of elements in the stack
2828
* @returns {number}
2929
*/
3030
size() {
3131
return this._elements.length;
3232
}
3333

3434
/**
35+
* Returns the top element in the stack.
3536
* @public
36-
* returns the top element in the stack
3737
* @returns {object}
3838
*/
3939
peek() {
@@ -43,17 +43,17 @@ class Stack {
4343
}
4444

4545
/**
46+
* Adds an element to the top of the stack.
4647
* @public
47-
* adds an element to the top of the stack
4848
* @param {object} element
4949
*/
5050
push(element) {
5151
this._elements.push(element);
5252
}
5353

5454
/**
55+
* Removes and returns the top element in the stack.
5556
* @public
56-
* removes and returns the top element in the stack
5757
* @returns {object}
5858
*/
5959
pop() {
@@ -63,36 +63,36 @@ class Stack {
6363
}
6464

6565
/**
66+
* Returns the remaining elements as an array.
6667
* @public
67-
* returns the remaining elements as an array
6868
* @returns {array}
6969
*/
7070
toArray() {
71-
return this._elements.slice(0);
71+
return this._elements.slice();
7272
}
7373

7474
/**
75+
* Clears all elements from the stack.
7576
* @public
76-
* clears all elements from the stack
7777
*/
7878
clear() {
7979
this._elements = [];
8080
}
8181

8282
/**
83+
* Creates a shallow copy from the stack.
8384
* @public
84-
* creates a shallow copy from the stack
8585
* @return {Stack}
8686
*/
8787
clone() {
88-
return new Stack(this._elements.slice(0));
88+
return new Stack(this._elements.slice());
8989
}
9090

9191
/**
92+
* Creates a stack from an existing array
9293
* @public
9394
* @static
94-
* creates a stack from an existing array
95-
* @param {array} elements
95+
* @param {array} [elements]
9696
* @return {Stack}
9797
*/
9898
static fromArray(elements) {

0 commit comments

Comments
 (0)