const splitArray=(arr, chunk)=>{
const elementInEachSubArray = Math.floor(arr.length / chunk)
const remainingElement = arr.length - (elementInEachSubArray * chunk)
let splitArray = Array.from({length: chunk}, ()=>[])
splitArray = splitArray.map(
(array, i)=>{
return arr.slice(i*elementInEachSubArray, elementInEachSubArray * (i + 1))
}
).map((array, i)=>[...array, arr[arr.length - remainingElement + i]].filter(Boolean))
console.log(splitArray)
}