From 02d98807f831bb312509c0b13540d751d08c0ae0 Mon Sep 17 00:00:00 2001 From: jony89 Date: Fri, 16 Feb 2018 21:59:33 +0200 Subject: [PATCH] fix unsupported sort since the logic within `getIntersection` depends on the values being sorted correctly (`arrayA[ai] < arrayB[bi]`) and .sort is not stable and even gives a wrong result according to decimal computation( [14,2].sort() = [14,2], so we must at least give the `compareFunction` for simple cases (which fits to our needs, as we compare Ids). --- src/bloodhound/search_index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bloodhound/search_index.js b/src/bloodhound/search_index.js index 0577c4fbf2..472ab4495f 100644 --- a/src/bloodhound/search_index.js +++ b/src/bloodhound/search_index.js @@ -168,8 +168,12 @@ var SearchIndex = window.SearchIndex = (function() { function getIntersection(arrayA, arrayB) { var ai = 0, bi = 0, intersection = []; - arrayA = arrayA.sort(); - arrayB = arrayB.sort(); + arrayA = arrayA.sort(function(a, b) { + return a - b; + }); + arrayB = arrayB.sort(function(a, b) { + return a - b; + }); var lenArrayA = arrayA.length, lenArrayB = arrayB.length;