2 Replies Latest reply on Apr 23, 2014 4:02 PM by MatLac

    Testing an array against another array

    MatLac Level 3

      -Four values from four text fields are put in an array named testArray

      -another array is created containing specific values that cannot be mixed named arrayVolVr.  [2222, 2223, 2224]

      -I want to test the values of testArray against those of arrayVolVr


      //Does testArray has more than one value and is one of them in arrayVolVr?

      for ( i = 0; i <= (testArray.length-1); i++){

         if ((testArray.length > 1) && (arrayVolVr.indexOf(testArray[i]) != -1)){


      Now the part I have trouble with comes next.  A value from arrayVolVr can only be mixed with another value from the same array.  If an element of testArray is not found in arrayVolVr, (var illigalCode) must become true.  For testing that part, I believe I have to remove testArray[i] from testArray and return a new Array for testing the second part.  Obviously, I don't want to compare testArray[i] to himself but to the other elements of testArray:


      if testArray is [2222, 2223] it's fine because they both belong to arrayVolVr.


      if testArray is [2222, 3333] an error message will be triggered because 2222 cannot be mixed with 3333.


      I cannot modify the content of testArray because it needs to pass a serie of similar tests against other arrays one after the other in search of a possible conflict.


      I tried creating testArray2 without success, it returns an empty array.

      var testArray2 = new Array();

      testArray2 = testArray.splice(testArray[i], 1));


      should it be


      testArray2.push(testArray.splice(testArray[i], 1)));