Answer the question
In order to leave comments, you need to log in
How to do pattern validation in JavaScript?
Hello.
Need help. See an example:
var listResult = new Array(
[x,x,x,0,0,0,0,0,0],
[0,0,0,x,x,x,0,0,0],
[0,0,0,0,0,0,x,x,x],
[x,0,0,x,0,0,0,x,0],
[0,x,0,0,x,0,0,x,0],
[0,0,x,0,0,x,0,0,x],
[x,0,0,0,x,0,0,0,x],
[0,0,x,0,x,0,x,0,0]
);
var result = [0,2,0,1,1,1,0,2,2]; // == listResult[1]
var result2 = [1,0,2,1,2,0,2,0,1]; // == listResult[7]
Answer the question
In order to leave comments, you need to log in
What is your verification principle? How does [0,2,0,1,1,1,0,2,2] match [0,0,0,x,x,x,0,0,0]?
0 - any character x - same?
If the patterns do not change - write down the rules in code - a[3]==a[4] && a[4]==a[5]. If they change, then you have to iterate through the array, select all indices with x, and compare all the values of the target array. You can "precompile" the rules into a function if you want the check to be optimized. To do this, generate the text of the function (directly the line if(a[3]==a[4] && a[4]==a[5]) return true; else return false; and create a function based on it: javascript.ru/ function
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question