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.
One line's not always important. Every time you ask for the array's length, a function is called to provide it at runtime. If you break this up into multiple lines you can store the length as a const to be efficient and make it more readable at the same time.
What's up with this syntax & indenting though...
2 loops.. you don't need map.
What the map is doing in this example is taking the current element (x), the index of the current element (i), and the array that .map was called upon (arr) - the x, i, and arr are just variables that you can name whatever you wish but they will always reprsent the element, index, array in that order. Sometimes you only want the array when using a map, but the only way to do that is to include the element and index regardless.
However if you only need the element you can write something as simply as .map((x) => x ** num), ignoring the index and array.
You can read more about it on the MDN here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
I almost have the same solution, but I forgot about those unary operators. It was clever of you to use a unary operator in your reduce method to convert the strings to numbers.
It is way more readable
They are not the same. "value" variable is still an integer that was passed to a function. It wasn't changed. "arr" variable is an array of digits (as strings) that was created after you applied .toString() and .split() methods to "value".
"value" is a number type. Numbers do not have length property.
Hope this helps :)
Please use spoiler flag next time.
This comment is hidden because it contains spoiler information about the solution
just beautiful
nice
And since when being a mod makes me perfect? I stand corrected, it's not needed in this case.
This is really weird from a mod at 1kyu.. Have YOU tried the code without them? It works perfectly fine, and of course it does, because before the reduce he's calling a map, and what's returned in the callback from map is always a number, the cast back to number happens when you do the power, there's no need to cast again in the reduce.
Clever readable solution.
Unary operator to convert from strings to numbers, have you tried the code without them?
Loading more items...