Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import leven from 'js-levenshtein'
console.log(leven('first', 'first'), leven('first', 'mirst'), leven('first', 'asd'), leven('flase', 'false'))
.map(exp => [exp, levenshteinDistance(exp, actualValue)])
.filter(
function getStatementGroupScore (nodeA, nodeB, variables) {
const wordsA = getStatementWords(nodeA, variables)
const wordsB = getStatementWords(nodeB, variables)
let score = 0
for (const wordA of wordsA) {
for (const wordB of wordsB) {
const distance = levenshtein(wordA.value, wordB.value)
if (distance <= 1) {
score += (wordA.score + wordB.score) / 2
}
}
}
return score
}
.map(opt => {
return [opt, levenshtein(input, opt)] as [string, number];
})
.filter(([, distance]) => distance <= maxDistance)
.add('levenshtein', () => {
for (const word of words) {
for (const word2 of words) {
leven(word, word2)
}
}
})
.add('damerau levenshtein', () => {
(acc, curr) => {
const distance = leven(str, curr)
if (distance < acc.distance) {
return {
distance,
str: curr,
}
}
return acc
},
{