title: Javascript custom array prototype
body: <p>I have for example this multidimensional array:</p>
  
  <pre><code>MyArray[('A', 40, true), ('B', 20, false), ('C', 55, true), ('D', 17, true)]
  </code></pre>
  
  <p>and I'd like to implement a custom min() and max() prototype to get min and max only of thoses are 'true'... any trick? I'm stuck at it since I was thinking around .map() to extract a certain property but how to check if enabled to extract due of true/false property.</p>
  
  <hr>
  
  <p>Precisely, I did:</p>
  
  <pre><code>var MyArray = [];
  
  MyArray.push( {
     name: 'A',
     valueA: 40,
     valueB: 36,
     enabled: true
  });
  
  MyArray.push( {
     name: 'B',
     valueA: 20,
     valueB: 18,
     enabled: false
  });
  
  MyArray.push( {
     name: 'C',
     valueA: 55,
     valueB: 75,
     enabled: true
  });
  
  .
  .
  .
  </code></pre>
  
  <p>that's why I am looking for the max and min of ones that are with state true, excluding the ones that are false...</p>
  
  <p>I tried to implement:</p>
  
  <pre><code>Array.minElement = function(array, prop) {
      return Math.min.apply(Math,
                  array.filter(function(arr) { return arr['enabled']; })
                       .map(function(arr) { return arr[prop]; })
             );
  }
  
  Array.maxElement = function(array, prop) {
      return Math.max.apply(Math,
                  array.filter(function(arr) { return arr['enabled']; })
                       .map(function(arr) { return arr[prop]; })
             );
  }
  </code></pre>
  
  <p>so I should call like Array.minElement(MyArray, 'valueA') to obtain the minimum but looks like it doesn't work....and it should return the min... </p>
  
  <p>what I did wrong here?...</p>
  
  <p>Thanks at all
  Cheers
  Luigi</p>