True. For the same functionality you would want something like this:
function validateUsername(username) {
const isLengthValid = validateUsernameLength(username);
if (!isLengthValid) return false;
const isAlphanumeric = validateAlphanumeric(username);
if (!isAlphanumeric) return false;
const isUsernameTaken = checkUsernameExists(username);
if (isUsernameTaken) return false;
return true;
}
Or even this:
function validateUsername(username) {
return validateUsernameLength(username)
&& validateAlphanumeric(username)
&& !checkUsernameExists(username);
}
Which would only run checkUsernameExists if the tests before it pass. But it's somewhat pseudo code anyway. The point of db.query was to show the single responsibility.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
True. For the same functionality you would want something like this:
Or even this:
Which would only run
checkUsernameExists
if the tests before it pass. But it's somewhat pseudo code anyway. The point ofdb.query
was to show the single responsibility.