loading...

Discussion on: Daily Challenge #179 - Hide Phone Numbers

Collapse
avaq profile image
Aldwin Vlasblom

JavaScript:

const encryptNum = num => num.replace(/(\d[ .-]?){6}$/, x => x.replace(/\d/g, 'X'))

The first replace finds the last 6 digits, with or without trailing separators.
The resulting match undergoes another replace call to substitute any digits for X's.

The first expression can also be relaxed to allow any separators: /(\d[^\d]?){6}$/, or even any number of separators: /(\d[^\d]*){6}$/.

Collapse
alvaromontoro profile image
Alvaro Montoro

This is neat

Collapse
cirlorm_io profile image