Skip to content

Commit

Permalink
Improve documentation for slice 0 -1
Browse files Browse the repository at this point in the history
`pop()` in JavaScript returns the popped of element and not the shortened array. Clarify that `slice 0 -1` actually returns the array without the last element.
  • Loading branch information
ad-si authored Jan 13, 2024
1 parent 65cea00 commit a36a86a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Array.elm
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,12 @@ the end of the array.
slice 1 -1 (fromList [0,1,2,3,4]) == fromList [1,2,3]
slice -2 5 (fromList [0,1,2,3,4]) == fromList [3,4]
This makes it pretty easy to `pop` the last element off of an array:
`slice 0 -1 array`
This makes it easy to get a new array without the last element.
slice 0 -1 (fromList [0,1,2]) == fromList [0,1]
Like `pop()` in JavaScript, but returning the new array
instead of the popped of element.
-}
slice : Int -> Int -> Array a -> Array a
slice from to array =
Expand Down

0 comments on commit a36a86a

Please sign in to comment.