Javascript sort with function not working on iPhone

iphone, javascript

Solution

Your comparison function is broken: It should return a numerical value which has to be negative if `a < b`, zero if `a = b` and positive if `a > b`, ie

function(a, b) {
    return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
}

Your function returns `false` if `a.name < b.name`, which will be converted to `0` and therefore means the values should be regarded as equal. It shouldn't work at all, but if it does, this is by coincidence (ie depends on the sorting algorithm and/or input set).

Problem

When calling sort(function) in Javascript on an iPhone it doesn't seem to sort. For example: ``` devices.sort(function(a, b) { return a.name > b.name; }); ``` Are there some known limitations or can someone help me how to do this on an iPhone. It seems to work fine in Chrome, IE, Firefox.

Original source