1function splitArrayIntoChunksOfLen(arr, len) {
2 var chunks = [], i = 0, n = arr.length;
3 while (i < n) {
4 chunks.push(arr.slice(i, i += len));
5 }
6 return chunks;
7}
8var alphabet=['a','b','c','d','e','f'];
9var alphabetPairs=splitArrayIntoChunksOfLen(alphabet,2); //split into chunks of two
1let input = [1,2,3,4,5,6,7,8,9];
2let chunked = []
3let size = 2;
4
5for (let i = 0; i < input.length; i += size) {
6 chunked.push(input.slice(i, i + size))
7}
8console.log(chunked)
1//#Source https://bit.ly/2neWfJ2
2const chunk = (arr, size) =>
3 Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
4 arr.slice(i * size, i * size + size)
5 );
6console.log(chunk([1, 2, 3, 4, 5], 2));
7
8
1function __chunk(array, size) {
2 let chunkArray = [];
3 return function _chunk(chunk = array) {
4 if (chunk.length < size) {
5 return chunkArray.push(chunk) && chunkArray;
6 }
7 return chunkArray.push(chunk.slice(0, size)) && _chunk(chunk.slice(size));
8 };
9}
1let input = [1,2,3,4,5,6,7,8];
2let chunked = []
3let size = 2;
4
5Array.from({length: Math.ceil(input.length / size)}, (val, i) => {
6 chunked.push(input.slice(i * size, i * size + size))
7})
8
9console.log(chunked);
1const tips_vectorDistance = (x, y) =>
2 Math.sqrt(x.reduce((acc, val, i) => acc + Math.pow(val - y[i], 2), 0));
3console.log(tips_vectorDistance([15, 0, 5], [30, 0, 20]));
4