rules

In this example below you will see how to do a rules with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by Jason_, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Jason_ ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>rules</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="test"></div>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/Jason_/rules-gaRjBP */
div#test {
  
}

/*Downloaded from https://www.codeseek.co/Jason_/rules-gaRjBP */
var output = document.getElementById('test')

//[ one, two, three, four, five, six]




function updateOutPut(str) {
  output.innerHTML += str+"<br><br>"
}

function one(params) {  return true;  }
function two(params) {  return true; }
function three(params) {  return true; }

function four(params) { return true; }
function five(params) { return false; } 
 
function six(params) { return true; }
function seven(params) { return true; }

var rules = [ 
  [ one],
  [ two],
  [three],
  [four, five]

]

function checkRule(params, ruleSet) {
  if (ruleSet.length > 0) {
    if (ruleSet[0](params)) {
      ruleSet.shift();
      checkRule(params, ruleSet);
    }
  }
  
  console.log(ruleSet.length,ruleSet )
  
 return ruleSet.length
    
}

function canItPass(params, ruleSets) {
  return ruleSets.reduce(function(returnValue, ruleSet){
    return (returnValue += checkRule(params, ruleSet));
  }, 0) < 1
}


//var foo = engine({}, rules, [])
var baz = canItPass({},rules)

updateOutPut(baz)

Comments