Skip to content

Commit 899b224

Browse files
committed
TIL Ruby: One liner To Get First and Last Elements In An Array
Here's cool way to get the first and last elements of an array _in one liner_ using splat: ```ruby first, *, last = [1, 2, 3, 4, 5] first # => 1 last # => 5 ```
1 parent 31bd0e0 commit 899b224

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)