Skip to content

Commit

Permalink
changed the interpretation of toIndex in A::slice()
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Aug 4, 2021
1 parent a62593f commit 4b76392
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ $result = A::any(fn($x) => $x % 5 === 0, $data);
<details>
<summary>A::slice</summary>

#### Returns the elements of the given list from fromIndex (inclusive) to toIndex (exclusive)

</details>

<details>
Expand Down
4 changes: 2 additions & 2 deletions src/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 4b76392

Please sign in to comment.