score:2

Accepted answer

if your list is extremely long and you don't want to loop it more than once, you can do this all in one call:

<!doctype html>
<html>

<head>
  <script data-require="d3@4.0.0" data-semver="4.0.0" src="https://d3js.org/d3.v4.min.js"></script>
</head>

<body>
  <script>
    var input = [{
        x: new date("2014-01-01"),
        y: 1223
      }, {
        x: new date("2015-06-01"),
        y: 12
      }, {
        x: new date("2015-07-01"),
        y: 1025
      }, {
        x: new date("2015-08-01"),
        y: 125
      }, {
        x: new date("2017-01-01"),
        y: 143
      }],
      mindate = new date("2015-01-01"),
      maxdate = new date("2016-01-01");

    var minmax = d3.extent(input, function(d) {
      if (d.x <= mindate || d.x >= maxdate){
        return nan;
      }
      return d.y;
    })
    console.log(minmax);
  </script>
</body>

</html>

score:2

you have the possibility to filter the elements from within your array to fit the range of dates you need:

inputarray.filter(d => d.x > "2015-01-01" && d.x < "2016-01-01")

then you can map (transform) the filtered elements to transform them into their associated y value:

.map(d => d.y)

to finally get the min or max of the resulting array:

d3.min(..)

which gives:

var input = [
  {
    x: "2014-01-01",
    y: 1223 
  },
  {
    x: "2015-06-01",
    y: 12
  },
  {
    x: "2015-07-01",
    y: 1025
  },
  {
    x: "2015-08-01",
    y: 125
  },
  {
    x: "2017-01-01",
    y: 143
  }
 ]

var output = input
  .filter(d => d.x > "2015-01-01" && d.x < "2016-01-01")
  .map(d => d.y);

console.log("filter/map array: " + output);
console.log("min: " + d3.min(output));
console.log("max: " + d3.max(output));
<script src="https://d3js.org/d3.v5.min.js"></script>


Related Query

More Query from same tag