Explorar el Código

add stack documentation

feature/exceptions
mark hace 9 meses
padre
commit
ca30ca77b8
Se han modificado 1 ficheros con 18 adiciones y 2 borrados
  1. +18
    -2
      stack.js

+ 18
- 2
stack.js Ver fichero

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



Cargando…
Cancelar
Guardar