-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (37 loc) · 1.19 KB
/
index.js
File metadata and controls
37 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
function calucatematches(index, matches, value, possiblevalue) {
var nextarr = []
for(var j =0;j < matches.length;j++){
if(matches[j]["key"] < index && matches[j]["val"] === possiblevalue){
nextarr.push({
key: index,
val: possiblevalue + value
})
}
}
return nextarr
}
const count = (matched, index) => (match, string) => {
var oldMatch = matched
var newMatch = []
if(index === match.length) {
return matched.length
}
for(var i =0;i < string.length;i++){
if((match[index] === string[i]) && index === 0) {
newMatch.push({
key: i,
val: string[i]
})
}
if((match[index] === string[i]) && index > 0) {
var res = match.slice(0,index)
newMatch.push(...calucatematches(i, oldMatch, match[index], res))
}
}
index = index + 1
return count(newMatch,index) (match, string)
}
var M = 1000000007;
return ( count([], 0) (newName, oldName) ) % M
}