Javascript 获取两个数组交集(重复)的项列表,支持List

(function( window ){

var Utils = {

//TODO 判断两个JSON是否相等
equals : function( param ,param2){
return JSON.stringify(param) === JSON.stringify(param2);
},

//TODO 获取当前项在数组出现的个数
getCountByItem : function( objects,item){
var count = 0;
for(var i = 0;i < objects.length;i++){
if( this.equals(objects[i] , item ) ){
count++;
}
}
return count;
},
//TODO 获取两个数组交集的项列表,支持List<object> 代码格式:[{}]
getRepeatItems : function( objects,objects2 ){
var tempObjects = objects.concat(objects2);
var repeatItems = [];
for(var i = 0;i < tempObjects.length;i++){
var itemCount = this.getCountByItem( tempObjects,tempObjects[i] );
if( itemCount > 1 ){
repeatItems.push( tempObjects[i] );
tempObjects[i] = null;
}
}
return repeatItems;
}

};

window.Utils = Utils;

})( window );

相关文章:

  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-11-04
  • 2022-12-23
  • 2022-01-17
猜你喜欢
  • 2021-12-03
  • 2022-02-16
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案
粤ICP备22038628号Powered By WordPress