Skip to content

Instantly share code, notes, and snippets.

@AminBusiness
Created November 9, 2018 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AminBusiness/864fdf65d8f6ff3138e23ad299255cb3 to your computer and use it in GitHub Desktop.
Save AminBusiness/864fdf65d8f6ff3138e23ad299255cb3 to your computer and use it in GitHub Desktop.
<script id="jsbin-javascript">
//Challenge 8: Array Chunking
//Split an array into chunked arrays of a specific length
//ex. chunkArray
function chunkArray(arr, len)
{
// Init chunked arr
const chunkedArr = [];
let i = 0;
//Loop while the index is less than the array length
while(i < arr.length)
{
//Slice out from the index to the index plus the chunk length
// and push onto the chunked array
chunkedArr.push(arr.slice(i, i + len));
// increments by chunk length
i += len;
}
return chunkedArr;
}
function letterChanges(str) {}
//Call function
const output = chunkArray([1,2,3,4,5,6,7], 3)
console.log(output);
</script>
<script id="jsbin-source-javascript" type="text/javascript">//Challenge 8: Array Chunking
//Split an array into chunked arrays of a specific length
//ex. chunkArray
function chunkArray(arr, len)
{
// Init chunked arr
const chunkedArr = [];
let i = 0;
//Loop while the index is less than the array length
while(i < arr.length)
{
//Slice out from the index to the index plus the chunk length
// and push onto the chunked array
chunkedArr.push(arr.slice(i, i + len));
// increments by chunk length
i += len;
}
return chunkedArr;
}
function letterChanges(str) {}
//Call function
const output = chunkArray([1,2,3,4,5,6,7], 3)
console.log(output);</script>
//Challenge 8: Array Chunking
//Split an array into chunked arrays of a specific length
//ex. chunkArray
function chunkArray(arr, len)
{
// Init chunked arr
const chunkedArr = [];
let i = 0;
//Loop while the index is less than the array length
while(i < arr.length)
{
//Slice out from the index to the index plus the chunk length
// and push onto the chunked array
chunkedArr.push(arr.slice(i, i + len));
// increments by chunk length
i += len;
}
return chunkedArr;
}
function letterChanges(str) {}
//Call function
const output = chunkArray([1,2,3,4,5,6,7], 3)
console.log(output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment