add ability to sieve custom function

This commit is contained in:
filifa
2026-05-04 22:25:30 -04:00
parent 14b640b2e3
commit e57a1c0335
2 changed files with 24 additions and 1 deletions

View File

@@ -133,6 +133,14 @@ function sieveMultiples(p, q, l, r, y, sieve, quo, additive) {
}
}
function setCustomFunctionVisibility(e) {
const isHidden = e.target.value !== "custom";
document.querySelector("#custom-function-label").hidden = isHidden;
document.querySelector("#custom-function").hidden = isHidden;
document.querySelector("#custom-function-additive-label").hidden = isHidden;
document.querySelector("#custom-function-additive").hidden = isHidden;
}
function getFunc(func) {
switch (func.value) {
case "num-divisors":
@@ -149,6 +157,11 @@ function getFunc(func) {
return [littleOmega, true];
case "big-omega":
return [bigOmega, true];
case "custom":
const def = document.querySelector("#custom-function");
const isAdditive = document.querySelector("#custom-function-additive");
const f = new Function("p", "k", def.value);
return [f, isAdditive.checked];
default:
throw new Error("function not implemented!");
}
@@ -219,4 +232,5 @@ function calculate() {
result.appendChild(table);
}
document.querySelector("#function").addEventListener("change", (e) => setCustomFunctionVisibility(e))
document.querySelector("#enter").addEventListener("click", () => calculate())