Skip to content

Commit ae3685c

Browse files
committed
refactor: trim countBy
1 parent b4a7f8b commit ae3685c

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/UnderscoreCollection.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,9 @@ public function indexBy($fn)
236236

237237
public function countBy($fn)
238238
{
239-
$data = [];
240-
241-
foreach ($this->group($fn, true) as $index => $value) {
242-
$data[$index] = \count($value);
243-
}
244-
245-
return new static($data);
239+
return $this->group($fn, true)->map(function ($value) {
240+
return \count($value);
241+
});
246242
}
247243

248244
protected function group($fn, $isGroup = true)

0 commit comments

Comments
 (0)