Bläddra i källkod

add stack documentation

feature/exceptions
mark 9 månader sedan
förälder
incheckning
ca30ca77b8
1 ändrade filer med 18 tillägg och 2 borttagningar
  1. +18
    -2
      stack.js

+ 18
- 2
stack.js Visa fil

@@ -1,9 +1,20 @@
/**
* The Memeforth program stack.
*
* @class
*
* @param {Array<any>} [arr] The initial stack to use, as an array.
*/
class Stack {
constructor(arr) {
if (arr === undefined) this.stackArr = [];
else this.stackArr = arr;
}

/**
* Pop the top value from the stack. Removes the item from the stack in-place.
* @returns The value popped from the stack.
*/
pop() {
const popped = this.stackArr.pop();

@@ -15,8 +26,13 @@ class Stack {
return popped;
}

push(...args) {
this.stackArr.push(...args);
/**
* Push a value onto the top of the stack.
*
* @param {...any} values The values to push onto the stack.
*/
push(...values) {
this.stackArr.push(...values);
}
}



Laddar…
Avbryt
Spara