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>');
```
If you want to sort by ascending it should be the comparator function should return a - b not a.length - b.length because a.length - b.length the result will always be zero for all the alphabets of length 1. The result will be different for ['ab', 'a'] will produce ['a', 'ab'] because the length of first element in array is lesser than second element.

```
function longest(arr) {
  return arr.sort( (a,b) => {
    return a - b;
  });
}

```