title: Filtering an array with a function that returns a promise
body: <p>Given</p>
  
  <pre><code>let arr = [1,2,3];
  
  function filter(num) {
    return new Promise((res, rej) =&gt; {
      setTimeout(() =&gt; {
        if( num === 3 ) {
          res(num);
        } else {
          rej();
        }
      }, 1);
    });
   }
  
   function filterNums() {
     return Promise.all(arr.filter(filter));
   }
  
   filterNums().then(results =&gt; {
     let l = results.length;
     // length should be 1, but is 3
   });
  </code></pre>
  
  <p>The length is 3 because Promises are returned, not values. Is there a way to filter the array with a function that returns a Promise? </p>
  
  <p>Note: For this example, fs.stat has been replaced with setTimeout, see <a href="https://github.com/silenceisgolden/learn-esnext/blob/array-filter-async-function/tutorials/array-filter-with-async-function.js">https://github.com/silenceisgolden/learn-esnext/blob/array-filter-async-function/tutorials/array-filter-with-async-function.js</a> for the specific code.</p>