title: Can I use array.filter() to get sample elements from array?
body: <p>I am learning JavaScript and trying to apply it in statistical sampling.
  The function below does not work but assumes: </p>
  
  <ul>
  <li>array = population to study</li>
  <li>sample = sample drawn from population</li>
  <li>element = each observation from population</li>
  </ul>
  
  <pre><code>const generateSample = array =&gt; {
      var sample = []
      array.filter(element =&gt; {
              (element in sample) ? return null : sample = [...sample, element]
      })
  }
  
  </code></pre>