- Use String.prototype.slice() to grab the portion of the characters that will remain unmasked.
- Use String.padStart() to fill the beginning of the string with the mask character up to the original length.
- If num is negative, the unmasked characters will be at the start of the string.
- Omit the second argument, num, to keep a default of 4 characters unmasked.
- Omit the third argument, mask, to use a default character of '*' for the mask.
//#Source https://bit.ly/2neWfJ2 const mask = (cc, num = 4, mask = '*') => ('' + cc).slice(0, -num).replace(/./g, mask) + ('' + cc).slice(-num); console.log(mask(1234567890)); console.log(mask(1234567890, 3)); console.log(mask(1234567890, -4, '$'));
******7890 *******890 $$$$567890
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join