Created
December 26, 2021 10:25
-
-
Save sanslan/ec4c9c584db1e2c4ca679b1d41652758 to your computer and use it in GitHub Desktop.
This file contains 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
function maskify(credit_card){ | |
let credit_card_string = credit_card.toString() | |
let card_length = credit_card_string.length | |
if(card_length < 6){ | |
return credit_card_string | |
} | |
let card_characters_array = credit_card.split('') | |
let masked = card_characters_array.map( (char,index) =>{ | |
if(index === 0 || index > card_length -4){ | |
return char | |
} | |
if(Number.isInteger(parseInt(char))){ | |
return '#' | |
} | |
return char | |
}) | |
return masked.join('') | |
} | |
console.log(maskify('3454534A')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment