Specifications: Write a shorter function (words [] string) int that, given a slice of strings, returns the length of the shortest string in terms of bytes. To test it you can use the main shown in the image below.
What have you tried so far to solve this exercise? What are your troubles making it work? What output do you get? Which do you expect?
yes I start to write it but I cannot how to go on to solve it
Can you please be more specific? What exactly is it what you have problems with?
As you post some screenshot that looks as if it has been taken from a courses book or website, I assume you are asking us to do your home work. We usually do not do peoples home work, but instead help them to overcome their problems and therefore solve the exercise on their own, ultimately learning something in the process.
Also in general I assume, that everything necessary to solve such an assignment is explained in the recent coursematerial.
can I please have some advices or tips to solve it? I’m just asking for these
It is easier to give you the tips based on what you already have. Otherwise the tipp will be to implement a function that does whats asked for in the exercise.
Any other hint we might give you, might be something that you already know. A waste of time for both of us…
seems like you should do you school assignments by yourself
Hi,
This link may help you : https://www.golangprograms.com/golang-get-number-of-bytes-and-runes-in-a-string.html
The function is just a loop (like the one in your main() code) with a comparison to store the minimum value and return that value at the end.
Remember to initialize the value to compare with a large value.
I’m not doing your exercise… but if you can’t do it with my explanation…
What are your troubles making it work?
A good tip to handle any programming task:
Start by writing in plain words, what a person would need to do to solve the problem – we call this pseudocode.
If your task was to find the biggest prime number in a list it could read like this:
Get the first number in the list
Check if it is a prime number
yes: remember this number
Then repeat for all numbers in the list:
check if the number is a prime number
and check if the number is bigger than the remembered number
yes: replace the remembered number with the new one
after the list is complete, the remembered number is the solution
After that you can try to translate each line to go code and will have a solution, which you can test and refine.
- Do you have any existing code that you’ve started or that partially addresses the problem? Sharing this can help me understand your approach and suggest improvements.