let a = 3 + 5; // a = 8; Right? And same for all other operators.
But I can not do
let plus = +; I get an error, and
let plus = "+"; makes it a string so I can’t use it for operations.
So they’re not Numbers neither Strings which makes me wondering what is the type of operators? (If they have one).
And basically I’m trying to refactor some repeated code into a function for (+, -, *, / operations)
but I can’t find a way to say
function operation(array, index, operator) let result = array[index] operator array[index+1]; return result; operation(this.array, 3, +);
It’s been driving me crazy a little bit, thanks for your help me understanding.