Skip to content

Commit

Permalink
Improved:Kit.coalesce charset
Browse files Browse the repository at this point in the history
  • Loading branch information
CJex committed Jan 27, 2015
1 parent c0d45e1 commit 8608012
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Kit.js
Expand Up @@ -319,7 +319,15 @@ function coalesce(ranges) {
results.push(b);
return b;
});
return results;
return results.reduce(function (results,range) {
if (range.length===2 && range[0]===pred(range[1])) {
results.push(range[0]);
results.push(range[1]);
} else {
results.push(range);
}
return results;
},[]);
}

function chr(n) {return String.fromCharCode(n)}
Expand Down
4 changes: 4 additions & 0 deletions tests/KitTest.js
Expand Up @@ -28,6 +28,10 @@ function testCoalesce() {
ranges=K.classify(K.negate(['Aa','az'])).ranges;
results=K.coalesce(ranges);
assert.deepEqual(results,K.negate(['Az']));

ranges=K.classify(['ab','cd','xy']).ranges;
results=K.coalesce(ranges);
assert.deepEqual(results,['ad','x','y']);
}

function testIdUnique() {
Expand Down

0 comments on commit 8608012

Please sign in to comment.