Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active February 11, 2022 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/ce833946b437b5f3bb0c92995350d218 to your computer and use it in GitHub Desktop.
Save McLarenCollege/ce833946b437b5f3bb0c92995350d218 to your computer and use it in GitHub Desktop.

Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it.

Your task is to write a function maskify, which changes all but the last four characters of a given string into '#'. The space characters need to be igonered.

eg.

console.log(maskify('4207 9992 8701 4443')) 
should print `#### #### #### 4443`
console.log(maskify('abcdefghijklmnopqrstuvwxyz'));
should print `######################wxyz`
console.log(maskify('abcdefghijklmnopqrstuv       wxyz'));
should print `######################       wxyz`
console.log(maskify('abcdefghijklmnopqrstuv       w x  y   z'));
should print `######################       w x  y   z`
function maskify(str){
// write your code here
}
console.log(maskify('4207 9992 8701 4443'));//`#### #### #### 4443`
console.log(maskify('abcdefghijklmnopqrstuvwxyz'));// `######################wxyz`
console.log(maskify('abcdefghijklmnopqrstuv       wxyz'));//`######################       wxyz`
console.log(maskify('abcdefghijklmnopqrstuv       w x  y   z'));// `######################       w x  y   z`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment