diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..de350a61 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -5,24 +5,47 @@ class Queue { } canEnqueue() { - // ... your code goes here + if (this.queueControl.length < this.MAX_SIZE) { + return true + } else { + return false + } + } + isEmpty() { - // ... your code goes here + if (this.queueControl.length === 0) { + return true + } else { + return false + } + + } enqueue(item) { - // ... your code goes here + if (this.canEnqueue() === true) { + this.queueControl.push(item) + return this.queueControl + } else { + throw new Error('QUEUE_OVERFLOW'); + } + } dequeue() { - // ... your code goes here + if (!this.isEmpty()) { + return this.queueControl.shift() + } else { + throw new Error('QUEUE_UNDERFLOW') + } + } display() { - // ... your code goes here - } + return this.queueControl + } } // This is required to enable the automated tests, please ignore it. diff --git a/src/queue/queue-dom.js b/src/queue/queue-dom.js index 236675b7..b2f0154f 100644 --- a/src/queue/queue-dom.js +++ b/src/queue/queue-dom.js @@ -34,14 +34,4 @@ const addToQueue = () => { // there was an overflow error, handle it } }; - -const removeFromQueue = () => { - try { - // ... your code goes here - } catch (error) { - // there was an underflow error, handle it - } -}; - -addQueue.addEventListener('click', addToQueue); -dequeue.addEventListener('click', removeFromQueue); +https://github.com/ironhack-labs/lab-js-chronometer/pull/677 \ No newline at end of file diff --git a/src/stack/stack-data-structure.js b/src/stack/stack-data-structure.js index 1106f6f3..b77018b3 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -5,25 +5,50 @@ class Stack { } canPush() { - // ... your code goes here + if (this.stackControl.length < this.MAX_SIZE) { + return true + } else { + return false + } + } isEmpty() { - // ... your code goes here + if (this.stackControl.length === 0) { + return true + } else { + return false + } + } push(item) { - // ... your code goes here + if (this.canPush() === true) { + this.stackControl.push(item) + return this.stackControl + } else { + throw new Error('STACK_OVERFLOW'); + } + } pop() { - // ... your code goes here + if (!this.isEmpty()) { + return this.stackControl.pop() + } else { + throw new Error('STACK_UNDERFLOW') + } + + } display() { - // ... your code goes here - } + return this.stackControl + } } // This is required to enable the automated tests, please ignore it. if (typeof module !== 'undefined') module.exports = Stack; + + +