function maskify(cc) {
return cc.replace(/.(?=.{4})/g, "#");
}
This is regex here /.(?=.{4})/
Any character followed by any character four times.
function maskify(cc) {
return cc.replace(/.(?=.{4})/g, "#");
}
console.log(maskify("Awesome"));
If any character is followed by four characters except newline then it will replace it with #
a is followed by weso, replace a with #
w is followed by esom, replace w with #
e is followed by some, replace e with #
After e there is no character which is follwed by 4 characters, so it won't replace it with #