Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
Protected Email - 1 or 2?
//Code one function protectedEmail(email) { var hiddenChars, hideEmail, j; for(let i = 0; i < email.length; i++) { if(email[i] == "@") { j = i; } } hiddenChars = email.slice(4, j); hideEmail = email.replace(hiddenChars, "..."); return hideEmail; } //Code two protected_email = function(user_email) { var avg, splitted, part1, part2; splitted = user_email.split("@"); part1 = splitted[0]; avg = part1.length / 2; part1 = part1.substring(0, (part.length - avg); part2 = splitted[1]; return part1 + "...@" + part2; } The code hides your email in this format "[email protected] outputs [email protected]". Which code is more efficient or better written, Code one or Code two?
3 Answers
+ 1
According to performance.now() both are almost equally efficient
0
RDC What is performance.now()?