marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

CH 4: array slice #342

Closed raduflp closed 6 years ago

raduflp commented 6 years ago

When the end index is not given, slice will take all of the elements after the start index.

this would suggest that [0, 1, 2, 3, 4].slice(2) should produce [3, 4] which is incorrect.

guifrrs commented 6 years ago

"Another fundamental array method is slice, which takes start and end indices and returns an array that has only the elements between them. The start index is inclusive, the end index exclusive."

Actually, that part is right before the example, but I get your point.

kapreski commented 6 years ago

it's clearly stated before the example: "The start index is inclusive, the end index exclusive." .slice(2) the index 2 is included..

raduflp commented 6 years ago

@guifrrs @kapreski i was just trying to think from the perspective of a newcomer to JS. When presenting a different scenario with only one argument one might not make a connection with the preceding inclusiveness note. So I think it would be reasonable to paraphrase in order to eliminate any confusion.

marijnh commented 6 years ago

I think this should be clear from context now.