Created
January 2, 2018 13:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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