title: verify (bitwise) if a value matches multiple specific flags of an enum
body: <p>I would like to check if a value corresponds to a set of flags (from an enum or object alike).</p>
  
  <p>Right now, I have come up with the following function in javascript (praise the snippet :3):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function hasFlags(flags, value) {
      let s = flags.reduce((sum, v) =&gt; sum += v, 0);
      
      return (s &amp; value) === s
  }
  
  FLAGS = {
      STEP_0: 1 &lt;&lt; 0,
      STEP_1: 1 &lt;&lt; 1,
      STEP_2: 1 &lt;&lt; 2,
      STEP_3: 1 &lt;&lt; 3,
      STEP_4: 1 &lt;&lt; 4,
      STEP_5: 1 &lt;&lt; 5,
      STEP_6: 1 &lt;&lt; 6,
      STEP_7: 1 &lt;&lt; 7
  }
  
  const needed = [
      FLAGS.STEP_2,
      FLAGS.STEP_3,
      FLAGS.STEP_6,
  ]
  
  console.log(hasFlags(needed, 4));                  // false
  console.log(hasFlags(needed, 8));                  // false
  console.log(hasFlags(needed, 64));                 // false
  console.log(hasFlags(needed, 4 + 8));              // false
  console.log(hasFlags(needed, 4 + 64));             // false
  console.log(hasFlags(needed, 8 + 64));             // false
  console.log(hasFlags(needed, 4 + 8 + 64));         // true
  console.log(hasFlags(needed, 4 + 8 + 64 + 1));     // true
  console.log(hasFlags(needed, 4 + 8 + 64 + 2));     // true
  console.log(hasFlags(needed, 4 + 8 + 64 + 1 + 2)); // true
  // etc...</code></pre>
  </div>
  </div>
  </p>
  
  <p>In python the function would look like this:</p>
  
  <pre><code>def hasFlags(flags, value):
      s = sum(flags)
      return (s &amp; value) == s
  
  print hasFlags((4,8,64), 4)  # False
  print hasFlags((4,8,64), 4+8+64)  # True
  # ...
  </code></pre>
  
  <p>Is there a better way (that is, more idiomatic ... or more pythonic) to do this same verification?</p>
  
  <p>Edit: Solutions in both python and javascript are appreciated, but I am  especially looking for an algorithm (whatever the language), as I've searched a lot across the web and never found any, while it seems to me that it's a common problem.</p>