Drill

ProblemsJavaScript › text

Hide most of an email address

easytextJavaScript

A support screen shows enough of the address for an agent to recognise it, without putting the whole thing on screen.

maskEmail(address: string) → string

Solve it in the editor →

Where you start

function maskEmail(address) {
  
}

Worked examples

CallResult
maskEmail("ahmet@example.com")"a****@example.com"
maskEmail("a@b.com")"a@b.com"
maskEmail("noatsign")"noatsign"
maskEmail("@x.com")"@x.com"

Hint

Find the @ first. Everything follows from where it is.

Reference solution in JavaScript
function maskEmail(address) {
  const at = address.indexOf('@');
  if (at <= 0) return address;
  return address[0] + '*'.repeat(at - 1) + address.slice(at);
}

The same problem in another language

More text problems in JavaScript