Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check one array if has values from other arrays in Typescript

how can I check if winningConditions are in chosenNumbers. As you see chosenNumbers are not same length and have a mix of number, and from this mix of number we got one condition 0, 3, 6. But there is also 2. How to check to make it work. I want to get true if i.e winning condition array [0, 3, 6] has same numbers as chosen numbers [0, 2, 3, 6], excluding 2 because it is out of scope. I hope you understand what I mean.

private chosenNumbers [0, 2, 3, 6]
private winningConditions = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6],
  ];

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m not sure this is the more efficient way to do it, but I think this function does what you’re asking for:

function check(chosenNumbers, winningConditions) {
  return winningConditions.some((condition) => {
    return condition.every((element) => {
      return chosenNumbers.includes(element);
    });
  });
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading