title: Why am I getting an unexpected behavior in my implementation of Promise.race()?
body: <p>I have the code for my Promise.race() implementation, <em>and it basically works</em>. However, in this case:</p>
  <pre><code>promiseRace([Promise.reject('test_error'), Promise.resolve('test_value')])
  </code></pre>
  <p>I am getting <code>test_value</code> instead of <code>test_error</code>.<br />
  Why it happens?</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>const promiseRace = promises =&gt; new Promise((resolve, reject) =&gt; {
    promises.forEach(p =&gt; {
      if (
        typeof p === 'object'
            &amp;&amp; 'then' in p
            &amp;&amp; typeof p.then === 'function'
      ) {
        p.then(resolve).catch(reject);
      } else {
        resolve(p);
      }
    });
  });
  
  promiseRace([Promise.reject('test_error'),
    Promise.resolve('test_value')]).then(value =&gt; { console.log(value); });</code></pre>
  </div>
  </div>
  </p>