Skip to content

Commit bf4c97f

Browse files
committed
Added concat
1 parent c6b53ce commit bf4c97f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,13 @@ FindIndex(users, "User1")
130130
FindIndex(users, "User5")
131131
//-1
132132
133+
```
134+
### Concat
135+
136+
```
137+
users1 := []User{{Id: 10, Name: "John"}, {Id: 11, Name: "Doe"}, {Id: 12, Name: "Sabrina"}}
138+
users2 := []User{{Id: 10, Name: "John"}, {Id: 11, Name: "Doe"}, {Id: 12, Name: "Sabrina"}}
139+
Concat(users1, users2)
140+
//{{Id: 10, Name: "John"}, {Id: 11, Name: "Doe"}, {Id: 12, Name: "Sabrina"}, {Id: 10, Name: "John"}, {Id: 11, Name: "Doe"}, {Id: 12, Name: "Sabrina"}}
141+
133142
```

concat_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package js_array_method
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestConcat(t *testing.T) {
8+
users1 := []User{{Id: 10, Name: "John"}, {Id: 11, Name: "Doe"}, {Id: 12, Name: "Sabrina"}}
9+
users2 := []User{{Id: 10, Name: "John"}, {Id: 11, Name: "Doe"}, {Id: 12, Name: "Sabrina"}}
10+
11+
users := Concat(users1, users2)
12+
13+
if len(users) != 6 {
14+
t.Errorf("Expected 6 got %d", len(users))
15+
}
16+
}

js_array_method.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ func Reverse[T any](input []T) []T {
120120

121121
return output
122122
}
123+
124+
func Concat[T any](slice1 []T, slice2 []T) []T {
125+
return append(slice1, slice2...)
126+
}

0 commit comments

Comments
 (0)