Javascript Sort Ordered Pairs Algorithmic Trading