diff --git a/src/Map.php b/src/Map.php index aeaf330..5557502 100644 --- a/src/Map.php +++ b/src/Map.php @@ -525,6 +525,8 @@ public function at( int $pos ) * The first line will return "3", the second and third one "2", the forth * one "30" and the last one "40". * + * NULL values are treated as 0, non-numeric values will generate an error. + * * This does also work for multi-dimensional arrays by passing the keys * of the arrays separated by the delimiter ("/" by default), e.g. "key1/key2/key3" * to get "val" from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to @@ -4661,6 +4663,8 @@ public function suffix( $suffix, int $depth = null ) : self * The first line will return "9", the second one "6", the third one "90" * and the last one "80". * + * NULL values are treated as 0, non-numeric values will generate an error. + * * This does also work for multi-dimensional arrays by passing the keys * of the arrays separated by the delimiter ("/" by default), e.g. "key1/key2/key3" * to get "val" from ['key1' => ['key2' => ['key3' => 'val']]]. The same applies to diff --git a/tests/MapTest.php b/tests/MapTest.php index dda829e..f85175a 100644 --- a/tests/MapTest.php +++ b/tests/MapTest.php @@ -142,7 +142,7 @@ public function testAvg() { $this->assertSame( 3.0, Map::from( [1, 3, 5] )->avg() ); $this->assertSame( 2.0, Map::from( [1, null, 5] )->avg() ); - $this->assertSame( 2.0, Map::from( [1, 'sum', 5] )->avg() ); + $this->assertSame( 2.0, Map::from( [1, 0.0, 5] )->avg() ); } @@ -3070,7 +3070,7 @@ public function testSuffix() public function testSum() { $this->assertSame( 9.0, Map::from( [1, 3, 5] )->sum() ); - $this->assertSame( 6.0, Map::from( [1, 'sum', 5] )->sum() ); + $this->assertSame( 6.0, Map::from( [1, 0.0, 5] )->sum() ); }