/**
* 对于由简单类型数据组成的对象为元素组成的数组进行去重操作
* @params {Array} 需要去重的对象数组
* @returns {Array} 去重后的对象数组
*/
function distinct(sourceArray) { var resultArray = [];
var i, j, currentSource, currentResult; for (i = 0; i < sourceArray.length; i++) { currentSource = sourceArray[i]; if (resultArray.length === 0) {
resultArray.push(currentSource);
continue;
} for (j = 0; j < resultArray.length; j++) { currentResult = resultArray[j]; if (!compare(currentResult, currentSource)) {
resultArray.push(currentSource);
} } } return resultArray; function compare(obj1, obj2) {
for (var prop in obj1) { if (!obj1.hasOwnProperty(prop)) {
continue;
} if (obj1[prop] !== obj2[prop]) {
return false;
} } return true;
} }
/**
* 对于由简单类型数据组成的对象为元素组成的数组进行去重操作
* @params {Array} 需要去重的对象数组
* @returns {Array} 去重后的对象数组
*/
function distinct(sourceArray) {
var resultArray = [];
var i, j, currentSource, currentResult;
for (i = ; i < sourceArray.length; i++) {
currentSource = sourceArray[i];
if (resultArray.length === ) {
resultArray.push(currentSource);
continue;
}
for (j = ; j < resultArray.length; j++) {
currentResult = resultArray[j];
if (!compare(currentResult, currentSource)) {
resultArray.push(currentSource);
}
}
}
return resultArray;
function compare(obj1, obj2) {
for (var prop in obj1) {
if (!obj1.hasOwnProperty(prop)) {
continue;
}
if (obj1[prop] !== obj2[prop]) {
return false;
}
}
return true;
}
}