Best way to select n elements at a time in jQuery
<p>I have an <code>ul</code> of <code>li</code> elements, what I want to do is this:</p>

<ol>
<li>If there are 6 or less <code>li</code> elements, select them all and put them into a new <code>ul</code>.</li>
<li>For any number greater than 6 elements, loop through, selecting 6 elements, put into new <code>ul</code>, start at the next <code>li</code> element and continue.</li>
<li>If there are less than 6 element left at the end, they get put into a new <code>ul</code> as well.</li>
</ol>

<p>If I start out with 5 <code>li</code> elements, I would hope to end up with 1 <code>ul</code> element with 5 <code>li</code> children.</p>

<p>If I start out with 40 <code>li</code> elements, I would hope to end up with 7 <code>ul</code> elements, 6 with 6 <code>li</code> children and 1 with 4.</p>

<p>What would be the most efficient way of handling this in jQuery?</p>
