The following code changes the values in an object to new values, but imposes a threshold limit for each property based on a third limits
object.
const oldValues = {
value1: 10,
value2: 20,
}
const newValues = {
value1: 1,
value2: 100,
}
const limits = {
value1: 20,
value2: 30,
}
const outputValues = {
value1: newValues.value1 < limits.value1 ? newValues.value1 : limits.value1,
value2: newValues.value2 < limits.value2 ? newValues.value2 : limits.value2,
}
// outputs: {value1: 1, value2: 30}
This works fine, but if I add a lot more properties, this code gets very repetitive and cumbersome to read. Is there a cleaner, shorter way to accomplish the same thing?