Menu
Coddy logo textTech

Length Function

Lesson 18 of 19 in Coddy's Functions and Pointers in Golang course.

Another useful function that we always use is the len() function, which returns the length of a given slice.

The usage of this function is very simple:

a := []int{1, 2, 3, 4, 5}
fmt.Println(len(a))

This will return 5.

 

 

challenge icon

Challenge

Easy

Let's build our length function! 😇

Write a function called length that takes a slice of type int and returns an int.

The function will iterate over the slice and return its length.

Refer to hints if you need more help 🤷‍♂️.

Try it yourself

// Your Code Here 

All lessons in Functions and Pointers in Golang