PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Split an array

const splitInto = n => (accm, value) => accm.every(e => e.length === n) ?
  [...accm, [value]] :
  [...accm.slice(0, -1), [...accm[accm.length - 1], value]]

Split an array into chunks with a specified size.

ex.

[1,2,3,4,5,6,7,8].reduce(sliceBy(2), [])
// -> [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7, 8 ] ]

[1,2,3,4,5,6,7,8].reduce(sliceBy(3), [])
// -> [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]
BETA Snippet explanation automatically generated by OpenAI:

Here is what the above code is doing:
1. It checks if the array is of length n.
2. If it is, then it pushes the value to the end of the array.
3. If it is not, then it slices the array and pushes the value to the end of the sliced array.
\

Snippet By mktoho

ยท

Created February 5th, 2022

ยท

Report Snippet