/**
* Created by Ashish Patel
* Copyright © 2017 ashish.me
* ashishsushilpatel@gmail.com
*/
/**
* Program:
* Write a function that splits an array (first argument) into groups the length of size (second argument) and
* returns them as a two-dimensional array.
*/
function chunkArrayInGroups(arr, size) {
const newarr = [];
for(let i = 0; i < arr.length; i+=size){
newarr.push(arr.slice(i,i+size));
}
return newarr;
}
console.log(chunkArrayInGroups(["a", "b", "c", "d", "e"], 2));
Created 2019-11-24T04:53:20+05:30 · Edit