TimSort in Javascript ported from TimSort.java of Android