Skip to content

Instantly share code, notes, and snippets.

@lhuria94
Created January 2, 2018 13:14
Show Gist options
  • Save lhuria94/c5f4d1c281ea968c3debd8ac457a28a5 to your computer and use it in GitHub Desktop.
Save lhuria94/c5f4d1c281ea968c3debd8ac457a28a5 to your computer and use it in GitHub Desktop.
Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it.
// Your task is to write a function maskify, which changes all but the last four characters into '#'.
// Examples
// maskify("4556364607935616") == "############5616"
// maskify( "64607935616") == "#######5616"
// maskify( "1") == "1"
// maskify( "") == ""
// "What was the name of your first pet?"
// maskify("Skippy") == "##ippy"
// maskify("Nananananananananananananananana Batman!") == "####################################man!"
// return masked string
function maskify(cc) {
return cc.replace(/.(?=.{4,}$)/g, '#');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment