Skip to content

Instantly share code, notes, and snippets.

@prmichaelsen
Last active July 6, 2021 03:20
Show Gist options
  • Save prmichaelsen/d1ddd0c347e39bd915f43a4626278199 to your computer and use it in GitHub Desktop.
Save prmichaelsen/d1ddd0c347e39bd915f43a4626278199 to your computer and use it in GitHub Desktop.
/**
* the stupidest way I could imagine to paginate
* an input array by pages with pageSize
*/
const paginate = (data, pageSize) => [
...Array(~~((data || []).length/pageSize)).keys()
].map(i => data.slice(i*pageSize , (i+1)*pageSize ));
// ~~ // floors a number
// [...Array(n).keys] => [0, 1, 2, ..., n - 2, n - 1]
// data || [] => short circuit--returns [] if data falsey
@prmichaelsen
Copy link
Author

jesus fuck i have no idea what this is doing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment