Skip to content

Instantly share code, notes, and snippets.

@amazingandyyy
Created January 7, 2020 21:33
Show Gist options
  • Save amazingandyyy/311517677957b0128dbb7f06e746ba86 to your computer and use it in GitHub Desktop.
Save amazingandyyy/311517677957b0128dbb7f06e746ba86 to your computer and use it in GitHub Desktop.
"1@23@@678@abc@".match(/(@*(\d|[abcd]){3,}@*)/g).join("").length === 13
@amazingandyyy
Copy link
Author

amazingandyyy commented Jan 7, 2020

testing: https://regex101.com/r/03qRen/1

const validateRunBoard = (board) => {
   for(i=0;i<board.length; i++){
      const row = board[i];
      if(!/@{13}/g.test(row)){
          // has cards on the row
          const isValid = row.match(/(@*(\d|[abcd]){3,}@*)/g).join("").length === 13;
          if(!isValid) return false;
      }
   }
   return true;
}

validateRunBoard(["@@@@@@@@@@@@@", "123456789abcd", "123@@678@abc@",  "@234@@789abcd", "@@@@@678@@@@@"]) // true
validateRunBoard(["@2@4567@9a@@@", "@2@4567@9abc@"]) // false

@amazingandyyy
Copy link
Author

amazingandyyy commented Jan 7, 2020

useful function

[true, true, false].every((i)=>i==true) // false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment