calcDistance.js
515 Bytes
/* eslint-disable no-restricted-syntax */
const levenshtein = require('js-levenshtein');
const Hangul = require('hangul-js');
exports.calcDistance = (word, profanityList) => {
let leastLevenshtein = 1000;
for (const profanity of profanityList[0]) {
let compareWord = Hangul.disassemble(profanity.content);
compareWord = compareWord.join('');
if (leastLevenshtein > levenshtein(word, compareWord)) {
leastLevenshtein = levenshtein(word, compareWord);
}
}
return leastLevenshtein;
};