This commit is contained in:
Alexander Pivkin 2025-08-28 15:57:11 +03:00
parent f88a392425
commit ce7565827e
5 changed files with 56 additions and 6 deletions

View File

@ -3,7 +3,6 @@ package main
import ( import (
"fmt" "fmt"
"main/sub" "main/sub"
"os"
) )
func jp (mylist ...int) { func jp (mylist ...int) {
@ -13,10 +12,10 @@ func jp (mylist ...int) {
} }
func main() { func main() {
args := os.Args[1] // args := os.Args[1]
res := sub.Kek(args) // res := sub.Kek(args)
fmt.Println(res) // fmt.Println(res)
res := sub.Kek("data.txt")
jp(1,2,3,4) jp(res...)
} }

9
headFirst/maps/data.txt Normal file
View File

@ -0,0 +1,9 @@
Alexander
Alexey
Andrew
Vitaly
Alexander
Vitaly
Sergey
Sergey
Alexander

3
headFirst/maps/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main
go 1.24.5

18
headFirst/maps/main.go Normal file
View File

@ -0,0 +1,18 @@
package main
import (
"fmt"
"main/sub"
)
func main() {
counter := make(map[string]int)
ret := sub.Kek("data.txt")
for _,name := range ret {
counter[name]++
}
for key,val := range counter {
fmt.Println(key,val)
}
}

21
headFirst/maps/sub/sub.go Normal file
View File

@ -0,0 +1,21 @@
package sub
import (
"bufio"
"log"
"os"
)
func Kek(fileName string) []string {
var seg []string
file, err := os.Open(fileName)
if err != nil {
log.Fatal("Cannot open file")
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
seg = append(seg, scanner.Text())
}
file.Close()
return seg
}