Write a function that divides an array into chunks of size n, where n is the length of each chunk. code example

Example 1: array chunk javascript

let input = [1,2,3,4,5,6,7,8];
let chunked = []
let size = 2;

Array.from({length: Math.ceil(input.length / size)}, (val, i) => {
  chunked.push(input.slice(i * size, i * size + size))
})

console.log(chunked);

Example 2: array chunk javascript

const tips_vectorDistance = (x, y) =>
  Math.sqrt(x.reduce((acc, val, i) => acc + Math.pow(val - y[i], 2), 0));
console.log(tips_vectorDistance([15, 0, 5], [30, 0, 20]));