//** * Function that recieves a array and the rule to filter the itens on it * One sample: * function reduceToArray([],item=>item.id==1); * * Rule is to be a function that will have a item of the array as the parameter and his result is a boolean * like this for example: * function rule(item){ * return item.id ==1; * } * @Author Leonardocregis */ function reduceToArray (arr,rule){ if ( Array.isArray(arr)){ if (arr.length { if ( !Array.isArray(acc)){ let aux = acc ; acc = []; if (rule(aux)){ acc.push(aux); } } if (rule(curr)) acc.push(curr); return acc; }); } if (rule(arr)){ let newArr = []; newArr.push(arr); return newArr; } return []; };