-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.go
More file actions
40 lines (38 loc) · 664 Bytes
/
Copy pathindex.go
File metadata and controls
40 lines (38 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package piscine
func Index(s string, toFind string) int {
toFindCount := arrayCount(toFind)
secondIndex := 0
for _, l := range toFind {
for i1, i2 := range s {
if i2 == l {
if toFindCount == 1 {
return i1
} else if toFindCount > 1 {
for a := 0; a < toFindCount; a++ {
if s[i1+a] == toFind[a] {
secondIndex++
} else {
return -1
}
}
if secondIndex == toFindCount {
return i1
}
} else {
return -1
}
}
}
if secondIndex <= 0 {
return -1
}
}
return toFindCount
}
func arrayCount(s string) int {
count := 0
for i := range s {
count = i + 1
}
return count
}