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.
Easy to read and understand compared to the other solutions though it will have overall time complexity is O(n).
nice you are now 4kyu !!!! asking make you more smarter!
This comment is hidden because it contains spoiler information about the solution
Best solution, imho
Js array split and join method both use for loops underneath the hood making your solution have a time complexity of O(n + m) but solving in string without converting to array the for loop runs only once and gives a better solutions with O(n) time complexity.
This comment is hidden because it contains spoiler information about the solution
You have a point and I agree with you about the one-liner problem (even if it's going against what I wrote three years ago).
Nowadays I don't use bracket with one-liners that can be written on the same line of the
if
, often for early exits:Otherwise, I like to use brackets mostly to make all if-statements look the same. Consistency makes things easier to read in my opinion. (And clear rules are easier for a team to follow and for tools to enforce.)
Refactoring out a function whenever there are a few lines, Uncle Bob-style, is another discussion. :-)
I would not say, that it is best practice, it is coding conventions. And in the majority of coding conventions the brackets are demanded.
I had to work without brackets and I must say since then the code without brackets is much easier to read.
The main argument is allways, that you may add a line outside the conditional block. In my expierence this never happens. And if it happens your test should fail. And if you have to add lines to a conditional block, it maybe time to refactor a methode which a catchy name.
In case I want to read later on what the shifting was about: https://stackoverflow.com/a/16155417/2848941
I would even go so far as to say that using the brackets are best practice. It's easy to start out with a one-liner and forget to put in the brackets when you add another line to the conditionaly block.
Brackets are optional for single line if statements (but some people prefer to add them for clarity).
How does this function work without the opening and closing {}'s after the conditional if statement?
That's not what EmilePW meant. Instead, the corner case
n = 2
isn't checked.2
is the only number which is both even and prime.Hi,
You only need to test if n is even, prime and multiple of 10.
Fixed. Square root is 2, therefore root(9, 2) == 3;
Loading more items...