Skip to content

Instantly share code, notes, and snippets.

@nhducit
Created December 8, 2016 11:04
Show Gist options
  • Save nhducit/2fb252afaac249ce8cb5da047bb5f902 to your computer and use it in GitHub Desktop.
Save nhducit/2fb252afaac249ce8cb5da047bb5f902 to your computer and use it in GitHub Desktop.
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