node-structures
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -6,3 +6,3 @@ /** | ||
/** | ||
* Constructor | ||
* Creates an empty Stack. | ||
* | ||
@@ -18,3 +18,3 @@ * @constructor | ||
* | ||
* @returns {Number} | ||
* @returns {Number} - the size of the stack. | ||
*/ | ||
@@ -26,5 +26,5 @@ Stack.prototype.size = function () { | ||
/** | ||
* Returns whether the stack is empty or not. | ||
* Tests if this stack is empty. | ||
* | ||
* @returns {boolean} | ||
* @returns {boolean} - true if and only if this stack contains no items; false otherwise. | ||
*/ | ||
@@ -36,14 +36,16 @@ Stack.prototype.isEmpty = function () { | ||
/** | ||
* Pushes the 'element' on the top of the stack. | ||
* Pushes an item onto the top of this stack. | ||
* | ||
* @param element | ||
* @param item - the item to be pushed onto this stack. | ||
* @return {boolean} - true if the item is pushed. | ||
*/ | ||
Stack.prototype.push = function (element) { | ||
return this.elements.push(element); | ||
Stack.prototype.push = function (item) { | ||
return !!this.elements.push(item); | ||
}; | ||
/** | ||
* Pops the top element of the stack & returns it. | ||
* Removes the object at the top of this stack and returns that object as the value of this function. | ||
* | ||
* @throws {Error} when the stack is empty. | ||
* @throws {Error} - if this stack is empty. | ||
* @return {*} - the object at the top of this stack (the last item of the Vector object). | ||
*/ | ||
@@ -54,12 +56,12 @@ Stack.prototype.pop = function () { | ||
var last = this.elements[this.size() - 1]; | ||
var item = this.elements[this.size() - 1]; | ||
this.elements.pop(); | ||
return last; | ||
return item; | ||
}; | ||
/** | ||
* Peeks the top element of the stack. | ||
* Looks at the object at the top of this stack without removing it from the stack. | ||
* | ||
* @throws {Error} when the stack is empty. | ||
* @returns {*} | ||
* @throws {Error} - if this stack is empty. | ||
* @returns {*} - the object at the top of this stack (the last item of the Vector object). | ||
*/ | ||
@@ -66,0 +68,0 @@ Stack.prototype.peek = function () { |
{ | ||
"name": "node-structures", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Albert Hambardzumyan", |
@@ -21,12 +21,41 @@ # node-structures | ||
# Usage | ||
###Stack | ||
```` javascript | ||
const Stack = require('node-structures').Stack; | ||
let stack = new Stack(); | ||
/** | ||
* Tests if this stack is empty. | ||
* @returns {boolean} - true if and only if this stack contains no items; false otherwise. | ||
*/ | ||
stack.isEmpty(); | ||
/** | ||
* Pushes an item onto the top of this stack. | ||
* @param item - the item to be pushed onto this stack. | ||
* @return {boolean} - true if the item is pushed. | ||
*/ | ||
stack.push(3); | ||
/** | ||
* Looks at the object at the top of this stack without removing it from the stack. | ||
* @throws {Error} - if this stack is empty. | ||
* @returns {*} - the object at the top of this stack (the last item of the Vector object). | ||
*/ | ||
stack.peek(); | ||
/** | ||
* Removes the object at the top of this stack and returns that object as the value of this function. | ||
* @throws {Error} - if this stack is empty. | ||
* @return {*} - the object at the top of this stack (the last item of the Vector object). | ||
*/ | ||
stack.pop(); | ||
stack.size() | ||
/** | ||
* Returns the size of the stack. | ||
* @returns {Number} - the size of the stack. | ||
*/ | ||
stack.size(); | ||
```` | ||
# License | ||
MIT |
@@ -24,3 +24,3 @@ /** | ||
var add = stack.push(7); | ||
expect(add).to.be.equal(1); | ||
expect(add).to.be.equal(true); | ||
}); | ||
@@ -59,3 +59,7 @@ it('should have length 2', function () { | ||
}); | ||
it('should throw an exception if the Stack is empty', function () { | ||
stack.pop(); | ||
expect(stack.pop.bind()).to.throw(Error); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8132
117
61