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
See: https://docs.codewars.com/training/troubleshooting#print-input
array || []
evaluates toarray
whenarray
is a truthy value and otherwise evaluates to an empty array.So,
array = array || []
will setarray
equal to an empty array if it does not already refer to an object.I think you've got things backwards. Your code returns true for 47 but should return false.
If the goal of the function is to return a sorted array, not returning one in some cases seems counter-productive to me.
https://docs.codewars.com/training/troubleshooting#error-messages-and-printing-your-inputoutput
I'm not arguing with your solutions, it tricked me in the first glance, so notice for everyone else:
Such function only applies caching to a current call.
It means if the function takes 7 seconds to complete, calling it 3 times, in total, will take 21 seconds.
I posted an explanation of this solution to evarx78's comment. I hope it will help you too.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
How many times do each of those numbers that 2 is a factor of occur?
what
s += tmp
is short fors = s + tmp
. So,s + tmp
is literally saved tos
for every iteration of the loop. This expression is not "inside a function call". The result of the evaluated expression (s
) is used as an argument to the function.Any code of the form:
can be rewritten as
Can someone explain this code ?
Take a close look at your alphabet.