Skip to content

Instantly share code, notes, and snippets.

@sanslan
Created December 26, 2021 10:25
Show Gist options
  • Save sanslan/ec4c9c584db1e2c4ca679b1d41652758 to your computer and use it in GitHub Desktop.
Save sanslan/ec4c9c584db1e2c4ca679b1d41652758 to your computer and use it in GitHub Desktop.
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