Use D3.min To Find Lowest Value That Is Not 0
I'm trying to use D3 to find the lowest value in my dataset. However, I also have values that are 0, but I want D3 to find the lowest value that is not 0. Currently I am using: d3
Solution 1:
You can use the constant Infinity
, since Math.min(Infinity, someNumber)
always return someNumber
(unless someNumber
is also infinity). So it'll look like this:
smallest = d3.min(data, function(d) {return d.houseValues || Infinity; })
If needed, you can check smallest == Infinity
, which would be true
in the case that all house values were 0.
Post a Comment for "Use D3.min To Find Lowest Value That Is Not 0"