Today a friend to interview was asked a question, prototype implementation of the array to heavy, at first blush is a bit of a mask, but carefully think of some inspiration
The array de-weight is not difficult, defining an empty array, traversing each item of the array to be removed, using flag as the identifier for determining if there is the same element in an empty array, and flag as true to add to the empty array
The prototype implementation, in fact, is to add a method to the array's prototype, so that the array to go to the heavy call the method
Array.prototype.remarr=function () {
var arr=[];
var len=this.length;
for (Var i=0;i<len;i++)
{
var flag=true
for (Var j=0;j<arr.length;j++)
{
if (This[i]==arr[j]) {
Flag=false;
}
}
if (flag)
{
Arr.push (This[i])
}
}
Return arr
}
Console.log ([1,2,3,3,2,1,5].remarr ())
JavaScript face test-prototype implements array de-weight