Toon2tech je zou zelfs een array kunnen maken en vanuit daar gewoon waarde voor waarde kunnen invoeren. Dus zonder formule maar een soort van lookup tabel. Dus een functie als zoiets:
`
function findNextValue(firstValue) {
// Define the table as an array of tuples
const table = [
[0, 28],
[5, 32],
[11, 36],
[19, 44]
];
// If the input exactly matches a first value in the table, return the second value
for (let i = 0; i < table.length; i++) {
if (table[i][0] === firstValue) {
return table[i][1];
}
}
// If the input falls between two values, perform interpolation
for (let i = 0; i < table.length - 1; i++) {
let x1 = table[i][0];
let y1 = table[i][1];
let x2 = table[i + 1][0];
let y2 = table[i + 1][1];
// Check if firstValue is between x1 and x2
if (firstValue > x1 && firstValue < x2) {
// Perform linear interpolation
let interpolatedValue = y1 + ((firstValue - x1) * (y2 - y1)) / (x2 - x1);
return interpolatedValue;
}
}
// If the first value is out of the bounds of the table, return null
return null;
}
// Example usage
console.log(findNextValue(0)); // Output: 28
console.log(findNextValue(7)); // Output: 33.3333 (Interpolated)
console.log(findNextValue(11)); // Output: 36
console.log(findNextValue(15)); // Output: 40 (Interpolated)
console.log(findNextValue(19)); // Output: 44
console.log(findNextValue(25)); // Output: null (Out of bounds)
`