Skip to content

Commit 4f53e78

Browse files
committed
Add Array Prepend Extension Function
1 parent 9661e98 commit 4f53e78

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Array Prepend Extension Function
2+
3+
extension Array {
4+
mutating func prepend(_ newElement: Element) {
5+
insert(newElement, at: 0)
6+
}
7+
}
8+
9+
[2, 3, 4, 5].prepend(1) // [1, 2, 3, 4, 5]
10+
["e", "l", "l", "o"].prepend("h") // ["h", "e", "l", "l", "o"]
137 KB
Loading

0 commit comments

Comments
 (0)