Skip to content

Instantly share code, notes, and snippets.

@Ruivilela
Created December 18, 2018 21:58
Show Gist options
  • Save Ruivilela/c5644f265c64e2258348d1945b06460f to your computer and use it in GitHub Desktop.
Save Ruivilela/c5644f265c64e2258348d1945b06460f to your computer and use it in GitHub Desktop.
Basic Algorithm Scripting: Chunky Monkey
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)
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