From f44d03c4c710d78bf134208738c0d41c0d27d717 Mon Sep 17 00:00:00 2001 From: Aktanusa Date: Sun, 27 Mar 2016 22:59:43 -0400 Subject: [PATCH] Added get method to the queue helper JS --- queue/queue.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/queue/queue.js b/queue/queue.js index 77c582d..6b56d66 100644 --- a/queue/queue.js +++ b/queue/queue.js @@ -66,5 +66,17 @@ function Queue(){ this.peek = function(){ return (queue.length > 0 ? queue[offset] : undefined); } + + /* Returns the item at the spot specified by place in the queue (without + * dequeuing it). If the queue is emprty or the requested place is outside + * the queue length then undefined is returned. + */ + this.get = function(place){ + var item = undefined; + if (queue.length > 0 && place < (queue.length - offset)) { + item = queue[(offset + place)]; + } + return item; + } }