Skip to content

Commit

Permalink
Fix NaN from showing up in empty results
Browse files Browse the repository at this point in the history
Closes GH-29.
  • Loading branch information
wooorm committed Feb 22, 2016
1 parent 1bb472a commit f915584
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/franc-all.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/franc-most.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/franc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/franc.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function normalize(value, distances) {
var length = distances.length;

while (++index < length) {
distances[index][1] = 1 - ((distances[index][1] - min) / max);
distances[index][1] = 1 - ((distances[index][1] - min) / max) || 0;
}

return distances;
Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ describe('franc.all()', function () {
}
);

it('should return `0` without matches', function () {
var result = franc.all('פאר טסי');

assert(result instanceof Array);
assert(result[0][0] === 'und');
assert(result[0][1] === 1);

result = franc.all('פאר טסי', {
'minLength': 3
});

assert(result instanceof Array);
assert(result[0][0] === 'heb');
assert(result[0][1] === 0);
assert(result[1][0] === 'ydd');
assert(result[1][1] === 0);
});

it('should return [["und", 1]] on an undetermined value', function () {
var result = franc.all('XYZ');

Expand Down

0 comments on commit f915584

Please sign in to comment.