diff --git a/README.md b/README.md index ea5bf4c..19e770b 100644 --- a/README.md +++ b/README.md @@ -514,6 +514,8 @@ $result = A::any(fn($x) => $x % 5 === 0, $data);
A::slice +#### Returns the elements of the given list from fromIndex (inclusive) to toIndex (exclusive) +
diff --git a/src/A.php b/src/A.php index 686d0e5..a76aa03 100644 --- a/src/A.php +++ b/src/A.php @@ -242,7 +242,7 @@ public static function tail(array $data): array { // A::init([1, 2, 3]) -> [1, 2] public static function init(array $data): array { - return self::slice(0, -1, $data); + return self::slice(0, self::length($data) - 1, $data); } // A::filter(x => x % 2 == 0, [1, 2, 3, 4, 5]) -> [2, 4] @@ -323,7 +323,7 @@ public static function contains($value, array $data): bool // A::slice(2, 4, [1, 2, 3, 4, 5]) -> [3, 4, 5] public static function slice(int $fromIndex, int $toIndex, array $data): array { - return array_slice($data, $fromIndex, $toIndex); + return array_slice($data, $fromIndex, $toIndex - $fromIndex); } // A::join('-', ['a', 'b', 'c']) -> 'a-b-c'