Quellcode durchsuchen

add stack documentation

feature/exceptions
mark vor 9 Monaten
Ursprung
Commit
ca30ca77b8
1 geänderte Dateien mit 18 neuen und 2 gelöschten Zeilen
  1. +18
    -2
      stack.js

+ 18
- 2
stack.js Datei anzeigen

@@ -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);
}
}



Laden…
Abbrechen
Speichern