Hey all,
after fumbling around all day I actually managed to pass the assignment of “Build an Email Masker” but I feel like I Frankensteined the whole thing together in a chaotic way.
Can you give me tips how to clean this up, or is it actually acceptable like this?
Thank you for your help ![]()
const email = “apple.pie@example.com”;
function maskEmail (email) {
let indexAt = email.indexOf(“@”);
let name = email.slice(1, indexAt -1);
let nameLength = name.length;
let star = “*”;
let maskedName = name.replace(name, star.repeat(nameLength));
let firstLetter = email.slice (0, 1);
let lastPart = email.slice (1 + nameLength);
return firstLetter + maskedName + lastPart;
}
maskEmail(email);
console.log(maskEmail(email))