File tree 1 file changed +40
-0
lines changed
solution/929.Unique Email Addresses
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ const numUniqueEmails2 = function ( emails ) {
2
+ const emailFilter = function ( str ) {
3
+ let index = str . search ( / @ / ) ;
4
+ let s = str . substring ( 0 , index ) ;
5
+ let s2 = str . substring ( index + 1 , str . length ) ;
6
+ let res = '' ;
7
+ for ( let i = 0 ; i < s . length ; i ++ ) {
8
+ if ( s [ i ] === '+' ) break ;
9
+ if ( s [ i ] === '.' ) continue ;
10
+ res = res + s [ i ] ;
11
+ }
12
+ return res + s2 ;
13
+ }
14
+
15
+ let arr = [ ] ;
16
+ for ( let i = 0 ; i < emails . length ; i ++ ) {
17
+ let t = emailFilter ( emails [ i ] ) ;
18
+ if ( arr . indexOf ( t ) === - 1 ) {
19
+ arr . push ( t ) ;
20
+ }
21
+ }
22
+ return arr . length ;
23
+ } ;
24
+
25
+ const numUniqueEmails = function ( emails ) {
26
+ let arr = emails . map ( str => {
27
+ let index = str . search ( / @ / ) ;
28
+ let s = str . substring ( 0 , index ) ;
29
+ let s2 = str . substring ( index + 1 , str . length ) ;
30
+ let res = '' ;
31
+ for ( let i = 0 ; i < s . length ; i ++ ) {
32
+ if ( s [ i ] === '+' ) break ;
33
+ if ( s [ i ] === '.' ) continue ;
34
+ res = res + s [ i ] ;
35
+ }
36
+ return res + s2 ;
37
+ } ) ;
38
+ let set = new Set ( arr ) ;
39
+ return set . size ;
40
+ }
You can’t perform that action at this time.
0 commit comments