0

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 "abcd1234@example.com outputs abcd...@example.com". Which code is more efficient or better written, Code one or Code two?

27th Sep 2020, 11:48 AM
Logos
Logos - avatar
3 Answers
+ 1
According to performance.now() both are almost equally efficient
27th Sep 2020, 11:58 AM
Raj Chhatrala
Raj Chhatrala - avatar
0
RDC What is performance.now()?
27th Sep 2020, 11:59 AM
Logos
Logos - avatar