callbackPractice uniq應該返回一個數組到所有重複被刪除的回調,但我缺少一些東西。請幫忙。我想刪除重複項並返回結果。我錯過了什麼?
function uniq(collection, fn) {
var uniqCollection = collection.filter(function(item, index, self) {
return self.indexOf(item) === index;
});
}
function uniq(collection, fn) {
var obj = {};
var uniqArr = [];
for (var key in obj) {
uniqArr.push(key);
}
return fn(uniqArr);
}
var names = ['Tyler', 'Cahlan', 'Ryan', 'Colt', 'Tyler', 'Blaine', 'Cahlan'];
uniq(names, function(uniqArr) {
console.log('The new names array with all the duplicate items removed is ', uniqArr);
});
請添加您收到的結果和/或錯誤... – tale852150
你有兩個名爲'uniq'的函數......你也沒有在第二個'uniq()'中使用'collection',而是總是迭代空的'obj'。 ..爲什麼兩個功能? – nem035