@@ -78,8 +78,10 @@ For the remainder of this documentation, we'll discuss each method available on
78
78
[ map] ( #method-map )
79
79
[ mapWithKeys] ( #method-mapwithkeys )
80
80
[ max] ( #method-max )
81
+ [ median] ( #method-median )
81
82
[ merge] ( #method-merge )
82
83
[ min] ( #method-min )
84
+ [ mode] ( #method-mode )
83
85
[ nth] ( #method-nth )
84
86
[ only] ( #method-only )
85
87
[ partition] ( #method-partition )
@@ -149,22 +151,15 @@ The `all` method returns the underlying array represented by the collection:
149
151
<a name =" method-avg " ></a >
150
152
#### ` avg() ` {#collection-method}
151
153
152
- The ` avg ` method returns the average of all items in the collection :
154
+ The ` avg ` method returns the [ average value ] ( https://en.wikipedia.org/wiki/Average ) of a given key :
153
155
154
- collect([1, 2, 3, 4, 5] )->avg();
156
+ $average = collect([['foo' => 10], ['foo' => 10], ['foo' => 20], ['foo' => 40]] )->avg('foo' );
155
157
156
- // 3
157
-
158
- If the collection contains nested arrays or objects, you should pass a key to use for determining which values to calculate the average:
159
-
160
- $collection = collect([
161
- ['name' => 'JavaScript: The Good Parts', 'pages' => 176],
162
- ['name' => 'JavaScript: The Definitive Guide', 'pages' => 1096],
163
- ]);
158
+ // 20
164
159
165
- $collection ->avg('pages' );
160
+ $average = collect([1, 1, 2, 4]) ->avg();
166
161
167
- // 636
162
+ // 2
168
163
169
164
<a name =" method-chunk " ></a >
170
165
#### ` chunk() ` {#collection-method}
@@ -739,6 +734,19 @@ The `max` method returns the maximum value of a given key:
739
734
740
735
// 5
741
736
737
+ <a name =" method-median " ></a >
738
+ #### ` median() ` {#collection-method}
739
+
740
+ The ` median ` method returns the [ median value] ( https://en.wikipedia.org/wiki/Median ) of a given key:
741
+
742
+ $median = collect([['foo' => 10], ['foo' => 10], ['foo' => 20], ['foo' => 40]])->median('foo');
743
+
744
+ // 15
745
+
746
+ $median = collect([1, 1, 2, 4])->median();
747
+
748
+ // 1.5
749
+
742
750
<a name =" method-merge " ></a >
743
751
#### ` merge() ` {#collection-method}
744
752
@@ -775,6 +783,19 @@ The `min` method returns the minimum value of a given key:
775
783
776
784
// 1
777
785
786
+ <a name =" method-mode " ></a >
787
+ #### ` mode() ` {#collection-method}
788
+
789
+ The ` mode ` method returns the [ mode value] ( https://en.wikipedia.org/wiki/Mode_(statistics) ) of a given key:
790
+
791
+ $mode = collect([['foo' => 10], ['foo' => 10], ['foo' => 20], ['foo' => 40]])->mode('foo');
792
+
793
+ // [10]
794
+
795
+ $mode = collect([1, 1, 2, 4])->mode();
796
+
797
+ // [1]
798
+
778
799
<a name =" method-nth " ></a >
779
800
#### ` nth() ` {#collection-method}
780
801
0 commit comments