Skip to content

Instantly share code, notes, and snippets.

@CreatiCoding
Last active June 23, 2020 02:31
Show Gist options
  • Select an option

  • Save CreatiCoding/d68c830835ef97d5a25c8eb43c30f153 to your computer and use it in GitHub Desktop.

Select an option

Save CreatiCoding/d68c830835ef97d5a25c8eb43c30f153 to your computer and use it in GitHub Desktop.
js array chunk function
// version 1 원본 훼손
const chunk = (list, size) =>
new Array(parseInt(list.length / size))
.fill()
.map(() => list.splice(0, size));
// version 2 원본 유지
const chunk = (list, size) =>
new Array(parseInt(list.length / size))
.fill()
.map((e, i) => list.slice(i * size, (i + 1) * size));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment