Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Dividi os itens de um array com base em um range onde é definido o limite de itens, o retorno são arrays com o número total de itens definidos.
- */
- var separar = (itens, maximo) => {
- return itens.reduce((acumulador, item, indice) => {
- var grupo = Math.floor(indice / maximo);
- acumulador[grupo] = [...(acumulador[grupo] || []), item];
- return acumulador;
- }, []);
- };
- // Teste de execução
- var itens = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
- console.log(JSON.stringify(separar(itens, 5)));
- console.log(separar(itens, 5));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement