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.
This comment is hidden because it contains spoiler information about the solution
For whole integer inputs, it will not round for obvious reasons. As for the latter, it is up to your own research.
i did format and mark as spoiler.
i dont understand why, when any other condition will round to 2 decimal places, or what you mean by casting to string type only
Because
1
rounded to 2 decimal places is still1
. If you want to add.00
to it, you will have to resort to other methods and not just casting it to string type onlyAlso, please mark your code as spoiler and use formatting when asking questions --> read this
This comment is hidden because it contains spoiler information about the solution
OP solved it, closing
dig this one
This comment is hidden because it contains spoiler information about the solution
Please use appropriate formatting when posting code. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
Your function returns an array of digits instead of a single number composed of those digits.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
what a beautifully thorough and graspable response. thank you so much.
This is known as an "arrow" function in JS, and for this particular example there isn't really a point. For simple cases there isn't a difference, it's just a stylistic choice. Many devs (including myself) prefer the arrow syntax because it's concise and much more readable in certain contexts. For example if I had a collection of things and I wanted to filter them by some criteria, I could write this with traditional "function declaration" syntax:
or with function expression syntax I could write:
or with arrow syntax I could simply write:
Now for more complex cases there are deliberate differences in functionality - arrow functions cannot be generators or constructors, for example, and they bind differently. It's okay if you're not familiar with those concepts yet, and it's definitely okay to be confused in general! You should become familiar with this syntax though; even if you dislike it yourself it's still going to pop up all over the place in other people's code.
Edit: There is a broader point to think about, too; in JavaScript functions are much like any other variable value and we often want to pass functions around. When filtering an array, as in the example above, the
filter()
function requires that you give it a function to apply to each element. To give a function to another piece of code, we often have to make that function into a variable.whats the point of naming a variable initialized as a function? i find that syntax incredibly confusing.