Q:

Write a JavaScript program to replace all but the last number of characters with the specified mask character

0

Write a JavaScript program to replace all but the last number of characters with the specified mask character. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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, '$'));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now