Let's imagine we have an HTML message list. Each item has index - Unix timestamp with milliseconds.
<ul>
<li ts="1657744925386">Item 1</li>
<li ts="1657744941061">Item 2</li>
<li ts="1657744953364">Item 3</li>
<li ts="1657744964372">Item 4</li>
<li ts="1657744973219">Item 5</li>
<li ts="1657744978450">Item 6</li>
</ul>
Then we have to insert another item, with ts=1657744950123. It should be after Item 3.
Is there an efficient way to calculate the new position in the list so that jQuery can insert the new element (because it requires a reference element relative to which will be inserted after or before the new element), given that there can be a lot of messages on the page and we don't have possibility to walk through all of them every time, making comparisons?