#5 Max Array Value

Emad Ibrahim
Jun 3, 2016 · 1 min read

If you have an array:

someArray: Ember.A([3,2,4,1])

You can get the maximum value with a computed property

maxNumber: Ember.computed.max('someArray')

The maxNumber property will always have the maximum value in the array and will auto re-compute and update any bindings automatically.
Here is some sample code:
https://ember-twiddle.com/43939812f6c9729845bff7072619c361?openFiles=controllers.application.js%2C

Bonus

You can get the minimum with

Ember.computed.min

See more at http://emberjs.com/api/classes/Ember.computed.html

Originally published at Ember Daily Tips.

    Emad Ibrahim

    Written by

    Husband, Father of Twins, Published Author, Entrepreneur, Passionate Technologist, Programmer and Productivity Nut. more at https://about.me/eibrahim