You are an expert programmer. Optimize this code

 const compactedGroups = groups.reduce((prev, cur) => {
 const isCurrentGroupHidden = cur.hidden;
 const previousGroup = prev.at(-1);
 const isPreviousGroupHidden =
 previousGroup === undefined ? isCurrentGroupHidden : previousGroup.hidden;

 if (isCurrentGroupHidden === isPreviousGroupHidden) {
 const newGroups = prev;
 if (newGroups.length === 0) {
 return [cur];
 }
 newGroups.at(-1)?.logs.push(...cur.logs);
 return newGroups;
 }
 return prev.concat(cur);
 }, []);
0982e39f-758c-4022-863c-7831af244eba
Вы опытный программист. Оптимизируйте этот код:

```javascript
const compactedGroups = groups.reduce((prev, cur) => {
const isCurrentGroupHidden = cur.hidden;
const previousGroup = prev.at(-1);
const isPreviousGroupHidden =
previousGroup === undefined ? isCurrentGroupHidden : previousGroup.hidden;

if (isCurrentGroupHidden === isPreviousGroupHidden) {
const newGroups = prev;
if (newGroups.length === 0) {
return [cur];
}
newGroups.at(-1)?.logs.push(...cur.logs);
return newGroups;
}
return prev.concat(cur);
}, []);
```

submitted
Вы экспертный программист. Оптимизируйте этот код const compactedGroups = groups.reduce(((prev, cur) => { const isCurrentGroupHidden = cur.hidden; const previousGroup = prev.at(-1); const isPreviousGroupHidden = previousGroup === undefined? isCurrentGroupHidden : previousGroup.hidden; if (isCurrentGroupHidden === isPreviousGroupHidden) { newGroups = prev; if (newGroups.length= 0) { { {current [cur]; } newGroups.at(-1?logs.push...cur.logs); return newGroups; } returngroup.con); }, [cat]);
{"source": "ewof/sharegpt-instruct-unfiltered-deduped", "kind": "human", "evolved_from": null}