Skip to content

Commit 89f816b

Browse files
authored
Create index.ts
1 parent 64fa9d3 commit 89f816b

File tree

1 file changed

+20
-0
lines changed
  • check-distances-between-same-letters

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default function checkDistances(s: string, distance: number[]): boolean {
2+
const mp=new Map<number,number>()
3+
4+
for(const [i,c]of Array.prototype.entries.call(s)){
5+
6+
7+
8+
const key=c.charCodeAt(0)-"a".charCodeAt(0)
9+
const last=mp.get(key)
10+
11+
if(mp.has(key)&&typeof last !=="undefined"&&i-last-1!==distance[key]){
12+
13+
return false
14+
15+
}else{
16+
mp.set(key,i)
17+
}
18+
}
19+
return true
20+
}

0 commit comments

Comments
 (0)