Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
In Golang we don't even have char.
"char" you created in your loop, represents a rune (an int32 value) of the string, not a byte or character. A rune is a code point in the Unicode character set.
When it checks char < '5' it compares the rune values
for example:
0 represents: 48
1 represents: 49
...
It compare with them like that
So your solution is correct but your fundamentals are wrong.
the thing is that this is a place for learning and this kata is like 7kyu. The person that resolved this kata like this is not doing this at a company or something of this nature and we don't know anything about this person's journey of learning programming. Can we be happy that people are learning programming and congratulate them about their progress?
It's not DRY and it's hard to read.
loops over all elements of
x
and stores the respective element inchar
.The underscore
_
is an empty placeholder for an indexing variable, which is not needed here.See also A Tour of Go - range
a long stream of pointlessly repetitive copy-pasted if statements, gross. it's bad. nobody said it needs to be in one line. the point is to be concise and clean.
This comment is hidden because it contains spoiler information about the solution
It's not efficient...
Yes, it's a valid solution. Some guys just feel better if they can diminish other people's work.