Queue = function Queue(...initialValues) {
const list = [];
if (initialValues) {
list.push(...initialValues);
}
this.size = function() {
return list.length;
}
this.peek = function peek() {
return list.length ? list[0] : null;
}
this.push = function push(value) {
if (Array.isArray(value)) list.push(...value);
else list.push(value);
return value;
}
this.pop = function pop() {
if (list.length > 0)
return list.pop();
else
return null;
}
this.find = function find(value) {
const index = list.indexOf(value);
if (index === -1)
return null;
else
return index;
}
this.print = function print(logger=console.log) {
const output = `Queue() <[${list.toString()}]>`;
return output;
}
}