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.
can anyone explain what's happening in the first two lines of the function body?
I understand it's setting up a loop (and I can read the conditional), but I don't understand what is exactly being done in terms of this syntax
can someone explain what is going on with [for _, char := range x]
? I can't reverse-search this pattern, and I don't know what precicely is happening here
Thanks for the support
Apparently, this site's community thinks less lines of code is "better", and there's not much of an understanding of readability or maintainability for these exercises... The mindset's divorced from practical coding, by and large.
This comment is hidden because it contains spoiler information about the solution
Yandere Simulator moment
When invoking string interpolation through
${var.function()}
Aren't we creating a new object, therefore, not mutating the original var? The declared string should be immutable in JS...I don't get the hate for this solution. It's pretty clear in terms of functionality. What's with the obsession of trying to write one-liners for everything?