0

I have one array something like following:

$scope.blinkedBoxes=[3,4,1,2,..]

It will have upto 8 elements in total (elements will be one of the numbers from 1,2,3,4).

Another array is like following:

$scope.clickedImages=[2,4,3,1,...]

I am building following function:

$scope.checkCrossCorrectness = function(array1, array2){}

My requirement is:

If the first element of $scope.blinkingBoxes is 2 (or basically any from 1, 2, 3, 4) then in $scope.clickedImages first element can not be 2 (or same as first element of first array), instead could be 1, 3, or 4. This logic continues for further elements as well (i.e. in first array at second position if 3 comes then in second array second position can be occupied by either 1, 2 or 4)

How can I implement this?

1
  • Uhm, and what should happen if the second array has the same number as the first array in the same index? Should it return true or false, or should it change the arrays, or should it launch a mission to Mars ... or ... it's not really clear what this function is supposed to do ? Commented Aug 2, 2016 at 21:10

1 Answer 1

1

I dont really know if this has anything to do with angular specifically, but from what I can tell a simple forEach loop will do to check equality between the indexes.

Example:

$scope.blinkedBoxes = [1, 2 ..] // etc
$scope.clickedImages = [2, 1, ..] // etc

function functionToRunOnClickOrWhatever(){
    $scope.blinkedBoxes.forEach(function(val, index){
        var isEqual = val === $scope.clickedImages[index];

        if(isEqual){
            // do something?
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.