As the post was written for people starting into the industry this is an example of clean code. You could argue this is cleaner:
privatebooltest(int x, int y){
if (x == y) returntrue;
returnfalse;
}
But this not as readable for someone who may have 0 experience in the industry and self taught. Separation of methods, naming and unnecessary code was mostly the point around this, being the SOLID principles as a developer.
If you prefer I can update this with more advanced understanding to keeping methods clean.
You second proposition is still the same antipattern. From my point of view, teaching antipatterns is wrong. Any live coding session will be a disaster for begginer with bad habits. Writing a code like this, during a job interview, is a red flag for me.
Proper (clean) version of IsHappy function should look like this (2 is magic number and should be moved to const).
Teaching SOLID principles is great (I know senior devs with problems with it), but do you really think, that refactoring lesson is good for absolute begginers? To refactor code one should know a little bit more about coding than pure basics.