1
Hello, I did an exercise in codewars and a solution caught my attention:
function padIt(str, n) {
while (n > 0) {
str = n-- % 2 ? '*' + str : str + '*';
}
return str;
}
I wonder, what exactly the condition within the while does.
More specifically the condition n-- % 2 ? ...
, shouldn’t be n-- % 2 == 1 ? ...
If 1 is already true, you don’t need the comparison. See more details in the yellow frame links.
– Bacco
@Bacco thank you so much! I’m sorry for asking a duplicate question, I must delete it?
– Edi Junior
Duplicates are for indexing. As it is positive, I see no reason to remove.
– Bacco