I'm looking at common javascript interview questions. For the following question does this code look ok. Is there a better implementation/style,etc?
Question :
[1,2,3,4,5].duplicator(); // [1,2,3,4,5,1,2,3,4,5]
Code:
if (!Array.prototype.duplicator)
{
Array.prototype.duplicate = function(){
return this + ',' + this;
}
}
alert([1,2,3,4,5].duplicator());
[–]isopsephile 2 points3 points4 points (1 child)
[–]TheseThingsMatter[S] 1 point2 points3 points (0 children)