I have an array with two values, (1 or 2) and (a, b, c or d). Depending on the two values a certain math function will execute. The function takes an separate inputted number and multiplies it by a constant, but that part isn't necessary to this.
Essentially a user provides the 3 values, I've already removed the one value which is the constant 'k', so I'm left with 2 values that determine the right multiplier for the constant 'k'.
I'm looking for something that would be easier and more robust than combining the array and running through all the possible solutions in a switch statement. There is a possibility of new variables for the array in the future.
let k = 5;
let input = [2, 'c'];
if (input.join().includes('1')) {
if (input.join().includes('a')) {
return k * 10;
};
else if (input.join().includes('b')) {
return k * 11;
};
else if (input.join().includes('c')) {
return k * 12;
};
else if (input.join().includes('d')) {
return k * 13;
};
};
else if (input.join().includes('2')) {
if (input.join().includes('a')) {
return k * 14;
};
else if (input.join().includes('b')) {
return k * 15;
};
else if (input.join().includes('c')) {
return k * 16;
};
else if (input.join().includes('d')) {
return k * 17;
};
};
Basically I have something like this right now. input and k are provided by the user, but not necessarily in any certain order, so I can't reliable assume input[1] will give me (a, b, c or d).
k * 15. So in that example, 'k' is the user input and '15' is the constant that doesn't change.