Question: I have HTML that looks like this:

```
    <table  cellspacing='0' border='0' width='100%'>
    <col align='left' />
    <tr>
    <td align='left'><font color='#FF0000'>Programming</font></td>
    </tr>
    </table>
    <table  cellspacing='0' border='0' width='100%'>
    <col align='left' />
    <col align='right' />
    <tr>
    <td align='left'><font color='#000000'>A1000</font></td>
    <td align='right'><font color='#008000'>D.Rogers</font></td>
    </tr>
    </table>

```

It is locally stored. I am trying to figure out how to data scrape "Programming","A1000" and "D.Rogers. How can I do this using Java and Jsoup?

Answer: 
You can add a default sorting with the position of the item of original array. (For better performance use [Sorting with map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Sorting_with_map).)

```js
function longest(arr) {
    var copy = arr.slice();
    return arr.sort(function (a, b) {
        return a.length - b.length || copy.indexOf(a) - copy.indexOf(b);
    });
}
var res = longest(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l']);
document.write('<pre>' + JSON.stringify(res, 0, 4) + '</pre>');
```
As stated [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Description):

> 
> If compareFunction(a, b) returns 0, leave a and b unchanged with
>  respect to each other, but sorted with respect to all different
>  elements. Note: the ECMAscript standard does not guarantee this
>  behaviour, and thus not all browsers (e.g. Mozilla versions dating
>  back to at least 2003) respect this.
> 
> 
> 

Keeping in mind that the return of the compare function in your example will always be 0, and also refering to the answers in [this](https://stackoverflow.com/questions/9831330/how-does-the-javascript-sort-function-workas-an-algorithm) topic you can see how different browsers itterate over elements differently. Therefore the results of your case are to be expected and probably varry from browser to browser