title: Javascript filter vs map problem
body: <p>As a continuation of my min/max across an array of objects I was wondering about the performance comparisons of filter vs map.</p>
  
  <p>So I put together a test on the values in my code as was going to look at the results in FireBug.</p>
  
  <p>This is the code:</p>
  
  <pre><code>var _vec = this.vec;
  min_x = Math.min.apply(Math, _vec.filter(function(el){ return el["x"]; }));
  min_y = Math.min.apply(Math, _vec.map(function(el){ return el["x"]; }));
  </code></pre>
  
  <p>The <code>map</code>ped version returns the correct result. However the <code>filter</code>ed version returns NaN. Breaking it out, stepping through and finally inspecting the results, it would appear that the inner function returns the <code>x</code> property of <code>_vec</code> but the actual array returned from <code>filter</code> is the unfiltered <code>_vec</code>.</p>
  
  <p>I believe my usage of <code>filter</code> is correct - can anyone else see my problem?</p>
  
  <p>Here's a simple test:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;S:GTC Map Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script type="text/javascript"&gt;
  function vector(x,y,z) { this.x = x; this.y =y; this.z=z; }
  var vec = [];
  vec.push(new vector(1,1,1));
  vec.push(new vector(2,2,2));
  vec.push(new vector(2,3,3));
  var _vec = vec;
  min_x = Math.min.apply(Math, _vec.filter(function(el){ return el["x"]; }));
  min_y = Math.min.apply(Math, _vec.map(function(el){ return el["x"]; }));
  
  document.write("&lt;br&gt;filter = " + min_x);
  document.write("&lt;br&gt;map = " + min_y);
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>