Skip to content

Commit 401fd66

Browse files
committed
Merge pull request #15 from futureworkz/splat
TIL Ruby: One liner To Get First and Last Elements In An Array
2 parents 31bd0e0 + 899b224 commit 401fd66

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# One liner To Get First and Last Elements In An Array
2+
3+
Here's cool way to get the first and last elements of an array _in one liner_ using splat:
4+
5+
```ruby
6+
first, *, last = [1, 2, 3, 4, 5]
7+
first # => 1
8+
last # => 5
9+
```

0 commit comments

Comments
 (0)