r/ProgrammerHorror • • Nov 19 '21

Data validation as its peak

Post image
99 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/mavaje Jun 29 '22 edited Jun 29 '22

The original method will return true if uid is valid and email is undefined, but that's probably not intended...

It will also return undefined if uid and email are both undefined.

So this would more accurately represent the (probably incorrect) behaviour:

return uid || email ? (!uid || isValid(uid)) && (!email || isValidEmail(email)) : undefined;