Last active
July 6, 2021 03:20
-
-
Save prmichaelsen/d1ddd0c347e39bd915f43a4626278199 to your computer and use it in GitHub Desktop.
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
/** | |
* 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jesus fuck i have no idea what this is doing