@@ -18,8 +18,8 @@ export const getSortData = arr => {
1818 return usable . concat ( disable )
1919}
2020// 反推字典表
21- export const getDictionary = ( name , word ) => {
22- word = word . replace ( / \s * / g , ' ')
21+ export const getDictionary = ( text , input ) => {
22+ let words = input . trim ( ) . split ( ' ')
2323 let res = [ ]
2424 const dfs = word => {
2525 let keys = [ ] , len = word . length
@@ -29,20 +29,25 @@ export const getDictionary = (name, word) => {
2929 }
3030 }
3131 let start = 0 , end = 0 , index = 0 , step = 0
32- if ( ! keys . some ( item => {
33- index = name . indexOf ( item )
34- if ( index === - 1 ) return false
35- if ( res . length && res . indexOf ( index ) > - 1 ) return false
36- start = word . indexOf ( item )
37- end = start + item . length
38- step = index + item . length
39- return true
40- } ) ) return false
32+ let flag = true
33+ for ( let key of keys ) {
34+ index = text . indexOf ( key )
35+ if ( index === - 1 ) continue
36+ if ( res . length && res . indexOf ( index ) > - 1 ) continue
37+ start = word . indexOf ( key )
38+ end = start + key . length
39+ step = index + key . length
40+ flag = false
41+ break
42+ }
43+ if ( flag ) return
4144 while ( step > index ) res . push ( index ++ )
4245 if ( start - 0 ) dfs ( word . slice ( 0 , start ) )
4346 if ( end - len ) dfs ( word . slice ( end , len ) )
4447 }
45- dfs ( word )
48+ for ( let word of words ) {
49+ dfs ( word )
50+ }
4651 return res
4752}
4853// 深拷贝 (这个随便复制的)
0 commit comments