Created
December 18, 2018 21:58
-
-
Save Ruivilela/c5644f265c64e2258348d1945b06460f to your computer and use it in GitHub Desktop.
Basic Algorithm Scripting: Chunky Monkey
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
| const chunkArrayInGroups = (arr, size) => ( | |
| arr.reduce( | |
| (acc, cv, index) => ( | |
| !((index / size) % 1) | |
| ? [a, [cv]] | |
| : [ | |
| ...acc.slice(0, acc.length - 1), | |
| [ | |
| ...acc[acc.length - 1], | |
| cv | |
| ] | |
| ] | |
| ), | |
| [] | |
| ) | |
| ) | |
| chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2) |
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
| https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/chunky-monkey/?fbclid=IwAR2K2LzyI3yKkHioeuyDOPkN8LUa_IINvDLlQdAXcfkzi0-DQ27jKbYkwx8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment