add ability to sieve custom function
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user