UNPKG

kantime-rule-engine

Version:

A library for custom validation in the form based on the user defined json schema.

75 lines (63 loc) 1.63 kB
// Stack class class Stack { constructor() { this.items = []; } //To add element to Stack push(element) { this.items.push(element); } //remove element from the Stack and return that //return Underflow when Stack is Empty pop() { if (this.items.length == 0) return "Underflow"; return this.items.pop(); } //return the First element without removing it peek() { if (this.isEmpty()) return "No elements in Stack"; return this.items[this.items.length - 1]; } //Return true if Stack is Empty isEmpty() { return this.items.length == 0; } //Return all elements in the Stack getStack() { return this.items; } } //Queue class class Queue { constructor() { this.items = []; } //To add element to Queue enqueue(element) { this.items.push(element); } //remove element from the Queue and return that //return Underflow when Queue is Empty dequeue() { if (this.isEmpty()) return "Underflow"; return this.items.shift(); } //return the First element without removing it front() { if (this.isEmpty()) return "No elements in Queue"; return this.items[0]; } //Return true if Queue is Empty isEmpty() { return this.items.length == 0; } //Return all elements in the Queue getQueue() { return this.items; } } module.exports = { Stack, Queue }