@@ -57,18 +57,18 @@ } } getSuggestions (nSuggLimit=10, nDistLimit=-1) { // return a list of suggestions - let lRes = []; - if (this.dSugg.get(0).length) { + if (this.dSugg.get(0).length > 1) { // we sort the better results with the original word - let dDistTemp = new Map(); - lRes.forEach((sSugg) => { dDistTemp.set(sSugg, str_transform.distanceDamerauLevenshtein(this.sWord, sSugg)); }); - lRes = lRes.sort((sA, sB) => { return dDistTemp.get(sA) - dDistTemp.get(sB); }); - dDistTemp.clear(); + this.dSugg.set(0, [...this.dSugg.get(0)].sort((a, b) => { return str_transform.distanceDamerauLevenshtein(this.sWord, a) - str_transform.distanceDamerauLevenshtein(this.sWord, b); })); + } + else if (this.dSugg.get(1).length > 1) { + this.dSugg.set(1, [...this.dSugg.get(1)].sort((a, b) => { return str_transform.distanceDamerauLevenshtein(this.sWord, a) - str_transform.distanceDamerauLevenshtein(this.sWord, b); })); } + let lRes = []; for (let [nDist, lSugg] of this.dSugg.entries()) { if (nDist > this.nDistLimit) { break; } lRes.push(...lSugg);