Results 1 to 4 of 4

Thread: Ext.Array.max incorrect

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha Premium User
    Join Date
    May 2012
    Posts
    19

    Default Ext.Array.max incorrect

    The Ext.Array.max is setting the max item where comparisonFn returns -1. However docs say: Note: gt = 1; eq = 0; lt = -1

    Code:
    max: function(array, comparisonFn) {            var max = array[0],
                    i, ln, item;
     
                for (i = 0, ln = array.length; i < ln; i++) {
                    item = array[i];
     
                    if (comparisonFn) {
                        if (comparisonFn(max, item) === -1) {
                            max = item;
                        }
                    }
                    else {
                        if (item > max) {
                            max = item;
                        }
                    }
                }
     
                return max;
            },

  2. #2
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,339

    Default

    Do you have a test showing how it could fail?

  3. #3
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    The docs also say it passes to the comparisonFn:

    Code:
    @param {Mixed} comparisonFn.max Current maximum value.
    @param {Mixed} comparisonFn.item The value to compare with the current maximum.
    So if the function returns -1, then that means the max is less than the compared item, so the compared item should become the max.

    https://fiddle.sencha.com/#view/editor&fiddle/2fmj
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #4
    Sencha Premium User
    Join Date
    May 2012
    Posts
    19

    Default

    Sorry, you are correct. It had been a long day...

Similar Threads

  1. [OPEN] Ext.Array. findBy incorrect index doc
    By LesJ in forum Ext JS 6.x Bugs
    Replies: 1
    Last Post: 8 Mar 2016, 1:42 PM
  2. Replies: 3
    Last Post: 5 Jan 2016, 11:09 PM
  3. Replies: 1
    Last Post: 15 Aug 2015, 10:14 AM
  4. Replies: 6
    Last Post: 1 Apr 2009, 8:12 AM
  5. Array.sortDates ,Array.unique, and extended Array.indexOf
    By wm003 in forum Ext 2.x: User Extensions and Plugins
    Replies: 3
    Last Post: 4 May 2008, 12:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •