File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 13
13
* list of valid options sorted based on their similarity with the input.
14
14
*/
15
15
export function suggestionList (
16
- input : string ,
17
- options : Array < string >
18
- ) : Array < string > {
19
- let i ;
20
- const d = { } ;
16
+ input : string ,
17
+ options : Array < string >
18
+ ) : Array < string > {
19
+ const optionsByDistance = Object . create ( null ) ;
21
20
const oLength = options . length ;
22
21
const inputThreshold = input . length / 2 ;
23
- for ( i = 0 ; i < oLength ; i ++ ) {
22
+ for ( let i = 0 ; i < oLength ; i ++ ) {
24
23
const distance = lexicalDistance ( input , options [ i ] ) ;
25
24
const threshold = Math . max ( inputThreshold , options [ i ] . length / 2 , 1 ) ;
26
25
if ( distance <= threshold ) {
27
- d [ options [ i ] ] = distance ;
26
+ optionsByDistance [ options [ i ] ] = distance ;
28
27
}
29
28
}
30
- const result = Object . keys ( d ) ;
31
- return result . sort ( ( a , b ) => d [ a ] - d [ b ] ) ;
29
+ return Object . keys ( optionsByDistance ) . sort (
30
+ ( a , b ) => optionsByDistance [ a ] - optionsByDistance [ b ]
31
+ ) ;
32
32
}
33
33
34
34
/**
You can’t perform that action at this time.
0 commit comments