The .reverse() function sorts the priorities alphabetically, not numerically
This is because Object.keys returns an array of strings.
If 2 findings have the same amount of matchpoints, the findings-entry gets overwritten. So the result isn't even valid.
Right, you want to push matches onto the array and sort it afterwards.
var findings = [];
for (var element in hugeObject) {
var points = getMatchPoints(inputToSearchFor, hugeObject[element]);
if (points) {
// It matched. At least a bit.
findings.push({ points: points, element: element });
}
}
findings.sort(function(a, b) { return ab.points - ba.points; });
Here I'm creating a new object with the number of match points stored in points and the found object stored in element, but you could store the point count directly in the found object if it makes more sense.