sellquiz
Version:
An open source domain-specific language for online assessment
50 lines • 2.69 kB
JavaScript
/******************************************************************************
* SELL - SIMPLE E-LEARNING LANGUAGE *
* *
* Copyright (c) 2019-2021 TH Köln *
* Author: Andreas Schwenk, contact@compiler-construction.com *
* *
* Partly funded by: Digitale Hochschule NRW *
* https://www.dh.nrw/kooperationen/hm4mint.nrw-31 *
* *
* GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 *
* *
* This library is licensed as described in LICENSE, which you should have *
* received as part of this distribution. *
* *
* This software is distributed on "AS IS" basis, WITHOUT WARRENTY OF ANY *
* KIND, either impressed or implied. *
******************************************************************************/
export function getHtmlChildElementRecursive(parentElement, childID) {
for (let i = 0; i < parentElement.children.length; i++) {
if (parentElement.children[i].id == childID)
return parentElement.children[i];
else if (parentElement.children[i].hasChildNodes()) {
let e = getHtmlChildElementRecursive(parentElement.children[i], childID);
if (e != null)
return e;
}
}
return null;
}
export function sellLevenShteinDistance(str1 = '', str2 = '') {
// 'code' taken from: https://www.tutorialspoint.com/levenshtein-distance-in-javascript
// TODO: copyright?????
const track = Array(str2.length + 1).fill(null).map(() => Array(str1.length + 1).fill(null));
for (let i = 0; i <= str1.length; i += 1) {
track[0][i] = i;
}
for (let j = 0; j <= str2.length; j += 1) {
track[j][0] = j;
}
for (let j = 1; j <= str2.length; j += 1) {
for (let i = 1; i <= str1.length; i += 1) {
const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
track[j][i] = Math.min(track[j][i - 1] + 1, // deletion
track[j - 1][i] + 1, // insertion
track[j - 1][i - 1] + indicator);
}
}
return track[str2.length][str1.length];
}
//# sourceMappingURL=help.js.map