Golang Tutorial #14 - Range & Slice/Array Examples

preview_player
Показать описание
This golang tutorial covers the range keyword and illsurates some common proramming problems and solutions that deal with arrays and slices.

◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python

◾◾◾◾◾◾

⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡

⭐ Tags ⭐
- Tech With Tim
- Golang Tutorial
- Go Range
- Arrays & Slices Golang
- Golang slices
- Go Arrays

⭐ Hashtags ⭐
#GO # Golang
Рекомендации по теме
Комментарии
Автор

Thanks bro, your lessons best, cause:
1. Just the most important inf.
2. Professional lector
3. Easy understanding spelling.

So, thank you for your spended time!

nb-cycw
Автор

That was a good approach, using the > operator to detect duplicates within the same slice. It's way more efficient than storing the duplicates.

msolomonbush
Автор

Thank u Tim, your explanation is great that someone new to programming like me can understand with ease. Appreciate man

anhtu
Автор

Hey thanks for making the code font size WAY bigger than default, for our benefit. Few do this.

thisisreallyme
Автор

adding break after you print will increase performance and only show the duplicates. great video!

TonoNamnum
Автор

this is good. slightly challenging for beginners to think and grow their skills with the basic syntax.

good teaching about the ways to deal with simple challenges using array/slice index, for loops, length, empty return, a more effective solution than to redo the same comparison on the same index.

bennylee
Автор

you can also acheive this by taking a slice of your slice:

for i, element := range a {
for _, element2 := range a[i+1:] {
if element == element2 {
fmt.Println(element)
}
}
}

jamisonwilliams
Автор

That's great Tim I code with python now I saw this video I really want to learn GOLANG

tunisiancommunityforcoders
Автор

this is my solution :)
var list = []int{1, 2, 3, 4, 5, 2, 4, 5}

for index, element := range list {
for _, subElement := range list[index+1:] {
if element == subElement {
fmt.Println(element)
}
}
}

محمدباقرملایی
Автор

After this series, Can we have some cool projects built in Golang?

dheerajlalwani
Автор

This will also work:
func main() {
mySlice := []int{1, 2, 3, 4, 5, 4, 6, 7, 8, 4, 9, 6, 9}
duplicates := make([]int, 0, len(mySlice))

fmt.Printf("The duplicates are: ")
for i, x1 := range mySlice {
for _, x2 := range mySlice[i + 1:] {
if x1 == x2 {
duplicates = append(duplicates, x2)
}
}
}
fmt.Println(duplicates)
}
but not for more than one duplicate, though, e.g. a third (fourth...) 6 or 4, in this example. As some people pointed out, Tim's algorithm also runs into this problem. Here I just wanted to show the use of element2 := range givenSlice[i + 1:] - making a slice of a slice that begins with the element that's one after the ith.

nenadilic
Автор

Hey 15:03 if u inject 3 same digit it will print wtf is it

Thelostblud
Автор

Is this another great video? ✌ always the best content✌ keep it going bro

michabilski
Автор

Why not just use slice in the second for like this? It would work the same way. (not trying to sound bitchy, just thought about this)
for i, element := range a {
for _, element2 := range a[i+1:] {
if (element == element2) {
fmt.Println(element)
}
}
}

Great job either way, thanks man!

KillFStudio
Автор

Try using this array/slice. {1, 3, 4, 56, 7, 112, 4, 9, 4, 99}. All thread 4's are being printed out. I think in this case we wanted only two 4's printed out. I could be wrong???

csharpusa
Автор

A good solution would have been to use a map, the number is the key and the count is the value.

rthu
Автор

Your code is wrong if there are more than two equal numbers, like, three of 4s. It would output several 4s.

Sergey_Latyshev
Автор

good job. would be great if you did something like an rest api with something light ( like chi), and that connects to a database.

opensourcerror
Автор

Damn, so much logic. Just have to use to set() in python lol.

oxyht
Автор

Do you think golang is gonna be the future Tim?

vishnurammageshvaran
welcome to shbcf.ru