Earlier quoted context omitted.
It is not illegal. Here’s Griggs v. Duke Power Co., 401 U.S. 424 (1971) https://supreme.justia.com/cases/federal/us/401/424/#tab-opi... . Go read it and see for yourself what it says.
Right at the top of that link: > Testing or measuring procedures cannot be determinative in employment decisions unless they have some connection to the job. IQ tests are not directly related to the job, and so are illegal according to that ruling. Coding tests are directly related, which is why they get a pass.
Do you scan source code and draw firm conclusions about what it does based on skim reading the first comment you see?
Perhaps my old contracts prof could have a second career as a google interviewer. (He was notorious for cold calling people that hadn’t briefed their cases and eating them alive.)