-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.tsx
39 lines (32 loc) · 961 Bytes
/
utils.tsx
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
38
39
import { Audio } from 'expo-av';
export const handlePlay = async (audioFilePath: string) => {
const soundObject = new Audio.Sound();
await soundObject.loadAsync({ uri: audioFilePath });
await soundObject.playAsync();
};
export const levenshteinDistance = (a: string, b: string): number => {
const matrix = [];
for (let i = 0; i <= b.length; i++) {
matrix[i] = [i];
}
for (let j = 0; j <= a.length; j++) {
matrix[0][j] = j;
}
for (let i = 1; i <= b.length; i++) {
for (let j = 1; j <= a.length; j++) {
if (b.charAt(i - 1) === a.charAt(j - 1)) {
matrix[i][j] = matrix[i - 1][j - 1];
} else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
}
}
}
return matrix[b.length][a.length];
};
export const removePunctuation = (word: string) => {
return word.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
}