File tree 3 files changed +67
-0
lines changed
solution/0800-0899/0831.Masking Personal Information
3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,30 @@ func maskPII(s string) string {
227
227
}
228
228
```
229
229
230
+ ### ** TypeScript**
231
+
232
+ ``` ts
233
+ function maskPII(s : string ): string {
234
+ const i = s .indexOf (' @' );
235
+ if (i !== - 1 ) {
236
+ let ans = s [0 ].toLowerCase () + ' *****' ;
237
+ for (let j = i - 1 ; j < s .length ; ++ j ) {
238
+ ans += s .charAt (j ).toLowerCase ();
239
+ }
240
+ return ans ;
241
+ }
242
+ let t = ' ' ;
243
+ for (const c of s ) {
244
+ if (/ \d / .test (c )) {
245
+ t += c ;
246
+ }
247
+ }
248
+ const cnt = t .length - 10 ;
249
+ const suf = ` ***-***-${t .substring (t .length - 4 )} ` ;
250
+ return cnt === 0 ? suf : ` +${' *' .repeat (cnt )}-${suf } ` ;
251
+ }
252
+ ```
253
+
230
254
### ** ...**
231
255
232
256
```
Original file line number Diff line number Diff line change @@ -196,6 +196,30 @@ func maskPII(s string) string {
196
196
}
197
197
```
198
198
199
+ ### ** TypeScript**
200
+
201
+ ``` ts
202
+ function maskPII(s : string ): string {
203
+ const i = s .indexOf (' @' );
204
+ if (i !== - 1 ) {
205
+ let ans = s [0 ].toLowerCase () + ' *****' ;
206
+ for (let j = i - 1 ; j < s .length ; ++ j ) {
207
+ ans += s .charAt (j ).toLowerCase ();
208
+ }
209
+ return ans ;
210
+ }
211
+ let t = ' ' ;
212
+ for (const c of s ) {
213
+ if (/ \d / .test (c )) {
214
+ t += c ;
215
+ }
216
+ }
217
+ const cnt = t .length - 10 ;
218
+ const suf = ` ***-***-${t .substring (t .length - 4 )} ` ;
219
+ return cnt === 0 ? suf : ` +${' *' .repeat (cnt )}-${suf } ` ;
220
+ }
221
+ ```
222
+
199
223
### ** ...**
200
224
201
225
```
Original file line number Diff line number Diff line change
1
+ function maskPII ( s : string ) : string {
2
+ const i = s . indexOf ( '@' ) ;
3
+ if ( i !== - 1 ) {
4
+ let ans = s [ 0 ] . toLowerCase ( ) + '*****' ;
5
+ for ( let j = i - 1 ; j < s . length ; ++ j ) {
6
+ ans += s . charAt ( j ) . toLowerCase ( ) ;
7
+ }
8
+ return ans ;
9
+ }
10
+ let t = '' ;
11
+ for ( const c of s ) {
12
+ if ( / \d / . test ( c ) ) {
13
+ t += c ;
14
+ }
15
+ }
16
+ const cnt = t . length - 10 ;
17
+ const suf = `***-***-${ t . substring ( t . length - 4 ) } ` ;
18
+ return cnt === 0 ? suf : `+${ '*' . repeat ( cnt ) } -${ suf } ` ;
19
+ }
You can’t perform that action at this time.
0 commit comments