Created
August 19, 2015 19:49
-
-
Save djm/7072b3adf10c68de5a9a to your computer and use it in GitHub Desktop.
Javascript: chunk an ES6 Map into an Array of similar sized Maps
This file contains hidden or 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
| export function chunkMap (map, chunkSize) { | |
| const chunkedMaps = [] | |
| const mapAsArray = Array.from(map) | |
| for (var i = 0; i < map.size; i += chunkSize) { | |
| let chunked = mapAsArray.slice(i, i + chunkSize) | |
| chunkedMaps.push(new Map(chunked)) | |
| } | |
| return chunkedMaps | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.