AS开发中如何求多个数组交集


这是个人在查找信息时发现一个用户提出的问题,正好也是自己想要了解的,曾经也遇到过,但没有有效地解决, 问题就是:

AS开发中经常会遇到数组求交集的问题, 同学们在这方面是否有好的方案?

   
  //以下面四个数组为例, 以供求交集
  
var A:Array=["1","2","3","4","5"];
var B:Array=["6","2","3","40","5","9"];
var C:Array=["4","2","3","0"];
var E:Array=["5","2","1","0"];
var D:Array=new Array();

as3 flex actionscript 算法 数组

MI‘饭’ 12 years, 7 months ago
   
  public static function getArrayPubSection(a:Array,b:Array,c:Array,d:Array):Array
  
{
var result:Array = [];
for each(var obj:Object in a)
{
if(b.indexOf(obj) >= 0 && c.indexOf(obj) >= 0 && d.indexOf(obj) >= 0)
{
result.push(obj);
}
}
return result;
}

路过ing answered 12 years, 7 months ago

Your Answer