function chunk(arr, size) {
// Break it up.
var tmpArray = [];
if(size<arr.length)
{
for (var i =0;i<arr.length ;i=size+i)
{
if(i+size>arr.length-1)
{
tmpArray.push(arr.slice(i,arr.length ));
}else
{
tmpArray.push((arr.slice(i,size + i)));
}
}
}else
{
return arr;
}
console.log(tmpArray);
return tmpArray;
}
chunk(["a", "b", "c", "d"], 2);
Bonfire: Chunky Monkey
最新推荐文章于 2024-09-25 08:24:58 发布