const quizzes = document.querySelectorAll(".calc__fields");
quizzes.forEach((quiz) => {
const questions = quiz.querySelectorAll(".fields__field"),
btnsPrev = quiz.querySelectorAll(".btn-prev"),
btnsNext = quiz.querySelectorAll(".btn--icon-next"),
stages = quiz.querySelectorAll(".fields__stage");
console.log(stages)
// progress
// const progressCount = questions.length;
btnsNext.forEach((btnNext, btnNextIndex) => {
btnNext.addEventListener("click", (e) => {
e.preventDefault();
questions[btnNextIndex].classList.remove("_active");
questions[btnNextIndex + 1].classList.add("_active");
stages[btnNextIndex].classList.remove("_active");
stages[btnNextIndex + 1].classList.add("_active");
});
if (!questions[btnNextIndex].classList.contains("_range")) {
btnNext.disabled = true;
}
});
btnsPrev.forEach((btnPrev, btnPrevIndex) => {
btnPrev.addEventListener("click", (e) => {
e.preventDefault();
questions[btnPrevIndex + 1].classList.remove("_active");
questions[btnPrevIndex].classList.add("_active");
});
});
questions.forEach((question, questionIndex) => {
if (questionIndex === 0) {
question.classList.add("_active");
} else {
question.classList.remove("_active");
}
question.addEventListener("change", (e) => {
const target = e.target,
inputsChecked = question.querySelectorAll("input:checked");
if (
inputsChecked.length > 0 ||
target.classList.contains("range__input")
) {
btnsNext[questionIndex].disabled = false;
} else {
btnsNext[questionIndex].disabled = true;
}
});
});
});
def Levenshtein_distance(a, b, levenstein_gap=2):
a, b = a.lower(), b.lower()
"Calculates the Levenshtein distance between a and b."
n, m = len(a), len(b)
if n > m:
# Make sure n <= m, to use O(min(n, m)) space
a, b = b, a
n, m = m, n
current_row = range(n + 1) # Keep current and previous row, not entire matrix
for i in range(1, m + 1):
previous_row, current_row = current_row, [i] + [0] * n
for j in range(1, n + 1):
add, delete, change = previous_row[j] + 1, current_row[j - 1] + 1, previous_row[j - 1]
if a[j - 1] != b[i - 1]:
change += 1
current_row[j] = min(add, delete, change)
return current_row[n] <= levenstein_gap