求一个数组数据不在另一个数组中的数据

来源:互联网 发布:程序员笔记本推荐 知乎 编辑:程序博客网 时间:2024/06/06 03:25
public static function eqObject(a:Object, b:Object):Boolean {
   if(a === b) {
    return true;
   }
   var bytesA:ByteArray = new ByteArray()
   bytesA.writeObject(a);
   var bytesB:ByteArray = new ByteArray()
   bytesB.writeObject(b);
   return eqByteArray(bytesA, bytesB);
  }
  public static function eqByteArray(a:ByteArray, b:ByteArray):Boolean {
   if(a.length != b.length) {
    return false;
   }
   var posA:int = a.position;
   var posB:int = b.position;
   var result:Boolean = true;
   a.position = b.position = 0;
   while(a.bytesAvailable >= 4) {
    if(a.readUnsignedInt() != b.readUnsignedInt()) {
     result = false;
     break;
    }
   }
   if(result && a.bytesAvailable != 0) {
    var last:int = a.bytesAvailable;
    result =
     last == 1 ? a.readByte() == b.readByte() :
     last == 2 ? a.readShort() == b.readShort() :
     last == 3 ? a.readShort() == b.readShort()
     && a.readByte() == b.readByte() :
     true;
   }
   a.position = posA;
   b.position = posB;
   return result;
  }
  
  /***
   * 
   *
   * 取出a1中a2不包含的数据;
   * **/
  public static function getArrayDiff(a1:Array,a2:Array):Array
  {
   for(var i:int=a1.length-1;i>=0;i--)
   {
    var o:Object=a1[i];
    a2.filter(function isExist(element:*, index:int, arr:Array):Boolean
    {
     if(eqObject(element,o))
     {
      a1.splice(i,1);
      return true
     }
     else
      return false
    }
     )
   }
   return a1;
  }
原创粉丝点击