From 97a58430a248b9ea89a7da0120cfceb0e6b11af5 Mon Sep 17 00:00:00 2001 From: Dobromir Ivanov Date: Wed, 7 Nov 2018 15:06:45 +0200 Subject: A (naive) golang implementation of a JavaScript lexer. (#18) Not that comments single line or multi line are not parsed. Numbers are parsed in the most naive way possible so don't expect miracles. --- homework/45180/input.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 homework/45180/input.js (limited to 'homework/45180/input.js') diff --git a/homework/45180/input.js b/homework/45180/input.js new file mode 100644 index 0000000..6974019 --- /dev/null +++ b/homework/45180/input.js @@ -0,0 +1,51 @@ +export default class Queue { + constructor() { + this._firstNode = null; + this._lastNode = null; + } + + dequeue() { + if (!this._firstNode) { + return this._firstNode; + } + + const payload = this._firstNode.payload; + + this._firstNode = this._firstNode.next; + + return payload; + } + + enqueue(item) { + const newNode = { + payload: item, + next: null + }; + + if (this._firstNode === null) { + this._firstNode = newNode; + this._lastNode = newNode; + + } else { + this._lastNode.next = newNode; + this._lastNode = newNode; + } + } + + clear() { + this._firstNode = null; + this._lastNode = null; + } + + top() { + if (!this._firstNode) { + return this._firstNode; + } + + return this._firstNode.payload; + } + + isEmpty() { + return !this._firstNode; + } +} -- cgit v1.3.1-26-gb76a