Amazon SDE 2 assessment - Need Solution Javascript - 2nd March, 2022

Task
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 will:

Mask all digits (0-9) with #, unless they are first or last four characters.
Never mask credit cards with less than 6 characters.
Never mask non-digit characters.
Examples
Input Output Comments
"4556364607935616" "4###########5616"
"4556-3646-0793-5616" "4###-####-####-5616"
"64607935616" "6######5616"
ABCD-EFGH-IJKLM-NOPQ ABCD-EFGH-IJKLM-NOPQ
A1234567BCDEFG89HI A#######BCDEFG89HI
"12345" "12345" No #s if less than 6 characters
"" "" Make sure to handle empty strings
"Skippy" "Skippy"
Documentation
maskify(cc)
Parameters:
cc: String
A string of any characters.

Guaranteed Constraints:
The input string will never be null or undefined.
Returns: String
The input string with all but the first and last four characters replaced with '#'

Comments (1)