Recap Challenge #2
Lesson 16 of 21 in Coddy's Slices and Maps in Golang course.
Challenge
EasyWrite a program that takes a slice of numbers and prints the largest value in it.
- In the given code, we define a slice of numbers.
- Using the
<strong>range</strong>keyword, loop over the slice to find the largest value
Try it yourself
package main
import (
"fmt"
)
func main() {
// Define a slice of numbers Don't Change this!
numbers := []int{34, 456, 200, 15, 30}
// Initialize the variable to hold the maximum value
// Iterate over the slice to find the maximum value
// Print the maximum value
fmt.Println("The maximum value:", max)
}All lessons in Slices and Maps in Golang
1Introduction
Introduction3Slices Behind the Scene
Slice is an ArraySlice with MakeCopy a SliceDelete an ElementRecap Challenge #1Recap Challenge #2