Skip to content

Commit 92923be

Browse files
committed
Minor refactoring
1 parent 30a783a commit 92923be

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/jsutils/suggestionList.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
* list of valid options sorted based on their similarity with the input.
1414
*/
1515
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);
2120
const oLength = options.length;
2221
const inputThreshold = input.length / 2;
23-
for (i = 0; i < oLength; i++) {
22+
for (let i = 0; i < oLength; i++) {
2423
const distance = lexicalDistance(input, options[i]);
2524
const threshold = Math.max(inputThreshold, options[i].length / 2, 1);
2625
if (distance <= threshold) {
27-
d[options[i]] = distance;
26+
optionsByDistance[options[i]] = distance;
2827
}
2928
}
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+
);
3232
}
3333

3434
/**

0 commit comments

Comments
 (0)