Is there a native JavaScript function that can handle this, or do I need to stick with the code provided below?
var arr = [1, 3, 4, '+', '-', or whatever]
function valueCheck(userClick) {
var operators = ['+', '-', '/', '*', '.'];
for (var i = 0; i < operators.length; i++) {
if (arr[arr.length - 1] == operators[i]) {
var value1 = 'operator found';
}
if (userClick == operators[i]) {
var value2 = value1;
alert("consecutive operators");
break;
}
}
}
While the current code accomplishes what I need it to do, I am curious if there might be a more concise way to achieve the same result. Essentially, I want to check if both the last element in the array and the user's click are present in the operators array:
if (arr[arr.length - 1] && userClick BOTH ARE IN operators array)
alert("consecutive operators")