Created
March 17, 2022 07:51
-
-
Save AhmedHelalAhmed/e52e67d3a09993140868007e148e795e to your computer and use it in GitHub Desktop.
refactoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createUser(email, password) { | |
validateInput(email, password); | |
saveUser(email, password); | |
} | |
function isNotValid(email, password) { | |
return emailNotValid(email) || passwordNotValid(password); | |
} | |
function emailNotValid(email) { | |
return !email || !email.includes("@"); | |
} | |
function passwordNotValid(password) { | |
return !password || password.trim() == ""; | |
} | |
function showErrorMessage(message) { | |
console.log(message); | |
} | |
function saveUser(user) { | |
const user = { | |
email: email, | |
password: password, | |
}; | |
database.insert(user); | |
} | |
function validateInput(email, password) { | |
if (isNotValid(email, password)) { | |
throw new Error("Invalid input"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createUser(email, password) { | |
if (!email || !email.includes("@") || !password || password.trim() == "") { | |
console.log("Invalid input!"); | |
return; | |
} | |
const user = { | |
email: email, | |
password: password, | |
}; | |
database.insert(user); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment