Here is the answer I think you are looking for. You need to determine when the last grouping is being made. then use the modo value to only wrap that many sections.
var divs = $(".someclass");
var limit = 10;//divs.length;
var grouper = 3
var modo = limit % grouper;
for(var i = 0; i < limit; i+=grouper) {
var offset = grouper;
if(modo + i === limit) {
offset = modo;
}
divs.slice(i, i+offset).wrapAll("<div class='classwrap' style='background-color:#def;'></div>");
}
OR
replace your initial selection with: Fiddle for slice
var limit = 10;
var divs = $(".someclass").slice(0,limit);