title: Remove item from array according to condition
body: <p>I have an array (given below). I want to remove files, if <code>minified</code> version of the same file exist.</p>
  <pre class="lang-js prettyprint-override"><code>var files = [&quot;foo.js&quot;, &quot;foo.min.js&quot;, &quot;bar.css&quot;,&quot;bar.min.css&quot;];
  
  // Should return: [foo.min.js&quot;, &quot;bar.min.css&quot;]
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>var files = [&quot;foo.js&quot;, &quot;foo.min.js&quot;, &quot;bar.css&quot;];
  
  // Should return: [foo.min.js&quot;, &quot;bar.css&quot;]
  
  </code></pre>
  <h1>What i have tried</h1>
  <pre class="lang-js prettyprint-override"><code>var files = [&quot;foo.js&quot;, &quot;bar.css&quot;];
  
  var tempUnMinified = [];
  var tempMinified = [];
  files.forEach(function (file) {
    if (file.endsWith(&quot;.min.js&quot;) || file.endsWith(&quot;.min.css&quot;)) {
      tempMinified.push(file);
    } else {
      tempUnMinified.push(file);
    }
  });
  
  tempUnMinified.forEach(function (unMinFile) {
    var tempRf = unMinFile.replace(&quot;.js&quot;, &quot;.min.js&quot;).replace(&quot;.css&quot;, &quot;.min.css&quot;);
    if (files.includes(tempRf)) {
      files.splice(files.indexOf(unMinFile), 1);
    }
  });
  
  console.log(files);
  
  </code></pre>
  <p>What i have tried does works, but i'm not sure if it works every time</p>
  <p>and so on.. Thanks in advance</p>