Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
write a function maskify, which changes all but the last four characters into '#'

Question:

write a function maskify, which changes all but the last four characters into '#'
Eg:
maskify('4556364607935616') # should return '############5616'
maskify('64607935616')      # should return '#######5616'
maskify('1')                # should return '1'
maskify('')                 # should return ''

Answer:

function maskify(input){
  return input.replace(/.(?=....)/g, '#')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.