Ebay Interview Question
Front-end Software EngineersCountry: United States
Interview Type: Phone Interview
Array.prototype.removeDup = function(){
var newArr = [], that = this;
that.forEach(function(item, index){
if (newArr.indexOf(item) == -1){
newArr.push(item);
}
})
//clear the original value and push unduplicated ones back
this.splice(0, this.length);
newArr.forEach(function(item, index){
that.push(item);
})
}
Array.prototype.removeDup = function(){
var newArr = [], that = this;
that.forEach(function(item, index){
if (newArr.indexOf(item) == -1){
newArr.push(item);
}
})
//clear the original value and push unduplicated ones back
this.splice(0, this.length);
newArr.forEach(function(item, index){
that.push(item);
})
}
- zhujy8833 June 27, 2012