Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Mask Digits

Beyond the Coursemedium

Implement `maskDigits(s)` replacing every digit with an asterisk.

Sample tests

Input: maskDigits("abc123")
Output: "abc***"
Input: maskDigits("12")
Output: "**"

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Omitting the global flag masks only the first digit.

Learning resources

  • MDN: Regular expressions
Visualize this concept: Regular Expressions →
Approach & explanation (try first)

replace(/\d/g, '*') swaps each digit for an asterisk.

Loading...
⌘/Ctrl + Enter

Run your code to see results.