Created
November 9, 2018 02:50
-
-
Save AminBusiness/864fdf65d8f6ff3138e23ad299255cb3 to your computer and use it in GitHub Desktop.
// source https://jsbin.com/gavovuh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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