Skip to content

Instantly share code, notes, and snippets.

@AhmedHelalAhmed
Created March 17, 2022 07:51
Show Gist options
  • Save AhmedHelalAhmed/e52e67d3a09993140868007e148e795e to your computer and use it in GitHub Desktop.
Save AhmedHelalAhmed/e52e67d3a09993140868007e148e795e to your computer and use it in GitHub Desktop.
refactoring
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");
}
}
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