I've worked on function that requires a heavy usage of if/else statement. I came up with an idea. Object with keys return the result.
const condition = {
up: x1 > x2 && y1 > y2,
down: x1 < x2 && y1 < y2
};
// or?
if (isUp) {
return x1 > x2 && y1 > y2;
}
return x1 < x2 && y1 < y2;Is using this conditional object is better than regular conditions? Some think this is crazy but bear with me, I was curious about the results.
- object with Condition took: 23.00499999546446 ms
- regular Condition took: 14.974999998230487 ms
For now, going to stick with conventional usage of regular condition statement.