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.
For that to work the value of s has to be saved to s for every loop
s += tmp is short for s = s + tmp. So, s + tmp is literally saved to s 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.
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.