@monorail hmmmmmmm
@monorail I think a while loop would be better but I'm not sure I would give enough of a shit in a code review because either way would look Weird
@wallhackio ??? Iterating i over a range of numbers is a very typical use for a for loop, why are you saying that a while loop would be better?!
@vaporeon_ @wallhackio it's advancing an index while those two mismatch
@vaporeon_ @alas oh I wouldn't have thought to do it with a do while, this is neat
my evil code golfing brain wants the i++ snuck into the previous line but that kind of thing tends to get you in trouble
by the way you also need i<matches[0].length in the conditional
@wallhackio @vaporeon_ @alas what it actually needs for my use case that i only realized later is to break on first === undefined || last === undefined || first !=== last
it's a "longest common prefix" algorithm
@monorail @wallhackio @alas So that it breaks when either of the arrays end, even if last is shorter than first? Is that the reason for checking the undefined? Can you also do that with
for (; i<matches[0].length&&i<matches[matches.length-1].length; i++)
Or am I making a stupid mistake again?
@vaporeon_ @wallhackio @alas i could but that's a lot of meaning to put on one line for me
@wallhackio @alas Augh. My brain really is not working today.
And see, this is why I would prefer a for-loop here. Iterate over all
iin a particular range and break early if some condition happens. Common pattern and less likely for me to make stupid mistakes about ranges or increments due to being sleepy.Really want to know how you would've written it with a while loop that's less hideous and ugly and wrong than what I've done.