Function

min (dependentKey) ComputedProperty public

Module: @ember/object
import { min } from '@ember/object/computed';
dependentKey
String
returns
ComputedProperty
computes the smallest value in the dependentKey's array

A computed property that calculates the minimum value in the dependent array. This will return Infinity when the dependent array is empty.

Example:

import { set } from '@ember/object';
import { mapBy, min } from '@ember/object/computed';

class Person {
  children = [];

  @mapBy('children', 'age') childAges;
  @min('childAges') minChildAge;
}

let lordByron = Person.create({ children: [] });

lordByron.minChildAge; // Infinity

set(lordByron, 'children', [
  {
    name: 'Augusta Ada Byron',
    age: 7
  }
]);
lordByron.minChildAge; // 7

set(lordByron, 'children', [
  ...lordByron.children,
  {
    name: 'Allegra Byron',
    age: 5
  }, {
    name: 'Elizabeth Medora Leigh',
    age: 8
  }
]);
lordByron.minChildAge; // 5

Classic Class Example:

import EmberObject, { set } from '@ember/object';
import { mapBy, min } from '@ember/object/computed';

let Person = EmberObject.extend({
  childAges: mapBy('children', 'age'),
  minChildAge: min('childAges')
});

let lordByron = Person.create({ children: [] });

lordByron.minChildAge; // Infinity

set(lordByron, 'children', [
  {
    name: 'Augusta Ada Byron',
    age: 7
  }
]);
lordByron.minChildAge; // 7

set(lordByron, 'children', [
  ...lordByron.children,
  {
    name: 'Allegra Byron',
    age: 5
  }, {
    name: 'Elizabeth Medora Leigh',
    age: 8
  }
]);
lordByron.minChildAge; // 5

If the types of the arguments are not numbers, they will be converted to numbers and the type of the return value will always be Number. For example, the min of a list of Date objects will be the lowest timestamp as a Number. This behavior is consistent with Math.min.

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fobject%2Fcomputed/min