Skip to content

Commit 7849de6

Browse files
committed
support splitter as a function while compare(simple compare)
1 parent a7904a5 commit 7849de6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/compare.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
var compare = function(cnt1, cnt2, splitter){
7-
var SPLITTER = splitter || '',
7+
var SPLITTER = typeof splitter === 'string' ? splitter : '',
88

99
MARK_EMPTY = -1,
1010
MARK_SAME = 0,
@@ -27,8 +27,14 @@ var compare = function(cnt1, cnt2, splitter){
2727
}
2828

2929
// convert string to array
30-
var arr1 = cnt1.split(SPLITTER),
30+
var arr1, arr2;
31+
if(typeof splitter === 'function'){
32+
arr1 = splitter(cnt1);
33+
arr2 = splitter(cnt2);
34+
}else{
35+
arr1 = cnt1.split(SPLITTER);
3136
arr2 = cnt2.split(SPLITTER);
37+
}
3238

3339
// caculate min distance & log each step
3440
var l1 = arr1.length,

0 commit comments

Comments
 (0)