array chunk javascript

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);let input = [1,2,3,4,5,6,7,8,9];
let chunked = []
let size = 2;

for (let i = 0;  i < input.length; i += size) {
  chunked.push(input.slice(i, i + size))
}
console.log(chunked)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]));
//#Source https://bit.ly/2neWfJ2 
const chunk = (arr, size) =>
  Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
    arr.slice(i * size, i * size + size)
  );
console.log(chunk([1, 2, 3, 4, 5], 2));

function splitArrayIntoChunksOfLen(arr, len) {
  var chunks = [], i = 0, n = arr.length;
  while (i < n) {
    chunks.push(arr.slice(i, i += len));
  }
  return chunks;
}
var alphabet=['a','b','c','d','e','f'];
var alphabetPairs=splitArrayIntoChunksOfLen(alphabet,2); //split into chunks of twofunction __chunk(array, size) {
  let chunkArray = [];
  return function _chunk(chunk = array) {
    if (chunk.length < size) {
      return chunkArray.push(chunk) && chunkArray;
    }
    return chunkArray.push(chunk.slice(0, size)) && _chunk(chunk.slice(size));
  };
}
Source

Also in JavaScript: