Есть ли способ уменьшить этот код, чтобы сделать то же самое, но с 100 символами меньше?Код двойной очереди должен быть уменьшен
Это простая двойная очередь, которая имеет pushHead, popHead, pushTail, popTail, а также способ доступа к длине и isEmpty.
var makeDeque = function()
{
var a= [];
this.length= a.length=0;
this.pushHead=function(v)
{
a.unshift(v);
}
this.popHead=function()
{
return a.shift();
}
this.pushTail=function(v)
{
a.push(v);
}
this.popTail=function()
{
return a.pop();
}
this.isEmpty=function()
{
return a.length===0;
}
return this;
};
Спасибо!
Посмотрите на http://stackoverflow.com/questions/18544265/pointers-and-array-class-in-javascript/18544420#18544420 – plalx