www.webdeveloper.com
Results 1 to 2 of 2

Thread: YAHOO.util.Sort.Compare

Hybrid View

  1. #1
    Join Date
    Oct 2013
    Posts
    1

    YAHOO.util.Sort.Compare

    Hi,

    Can anyone please explain how this YAHOO.util.Sort.Compare(a,b,desc) works.

    Thanks,

  2. #2
    Join Date
    Nov 2013
    Posts
    41
    Sort static utility to support Column sorting.

    Boolean compare ( a , b , desc ) Comparator function for simple case-insensitive string sorting.

    Parameters: a <Object> First sort argument. b <Object> Second sort argument. desc <Boolean> True if sort direction is descending, false if sort direction is ascending.

    Returns: Boolean Return -1 when a < b. Return 0 when a = b. Return 1 when a > b.
    From: http://developer.yahoo.com/yui/docs/YAHOO.util.Sort.

    You could use simple Javascript instead. Example:
    Code:
    var a = 9;
    var b = 2;
    
    if (a < b) {
      return "-1";
    }
    else if (a == b) {
      return "0";
    }
    else if (a > b) {
      return "1";
    }
    
    // Would return "1" because 9 is greater than 2 (b is greater than a)
    I'm not quite sure about the "desc", but setting it to true will probably just reverse the values. Experiment with it (jsFiddle is great for this) and see what it does.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles