javascript - Min of a couple of values which must not be 0 -
i need minimum of a
, b
, c
, d
. when 1 or more of them 0 fall out of comparison. solve if
/else
cascade kind of ugly. there cleaner way solve this? math.min
alone doesn't work because result in 0 when ever 1 of variables 0.
can put them in array , drop 0 in array? there math.min
arrays?
bestprice: ember.computed('a', 'b', 'c', 'd', function() { var = this.get('a'); var b = this.get('b'); var c = this.get('c'); var d = this.get('d'); return math.min(a, b, c, d); }),
example:
- a = 0
- b = 10
- c = 20
- d = 30
bestprice: 10
how this?
prices: ember.computed.collect('a', 'b', 'c', 'd'), bestprice: ember.computed('prices', function() { var nonzero = this.get('prices').filter(function (x) { return x > 0; }); return math.min.apply(null, nonzero); }),
Comments
Post a Comment