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.
Very clever but not the best practise! Big up man!
one thing to add, if you would rather settle for a built in method, always use indexOf() over includes()
This is a do / while loop simulated via recursion. A non-recursion equivalent might look like this:
Can anyone please help me understand the return statement, a ternary operator in this case, which in the else clause basically calls the function dirReduc(arr). How does this work, why don't we get "RangeError: Maximum call stack size exceeded."? I tested by removing the ternary operator and just returning the arr, and it worked, which makes more sense to me. If it work, why did the authors of solutions of this kata use the ternary operator instead of just returning the arr?
copy that, ty
This comment is hidden because it contains spoiler information about the solution
Click the "View Solution" link under my comment.
This comment is hidden because it contains spoiler information about the solution
How can this be done without
indexOf
?.
I think the same can be done like this:
return root%1 ? -1 : Math.pow(++root, 2);
since root%1 would return a non zero value (i.e. it's remainder) if it not completely divisible.
This comment is hidden because it contains spoiler information about the solution
The expected return values are not consistent with the problem statement.