+ 3
How do you add/subtract/multiply/divide an arrays elements
If I have this array how could I multiply its elements together so it results in 16? var equation = new Array(8, "*", 2);
9 Réponses
+ 11
but it works😳 silent, where I forgot one eval?
+ 10
var equation = new Array(8, "*", 2);
var multiply = 0;
var eqLength = equation.length;
for(var i = 0; i < eqLength; i++) {
multiply += equation[i];
}
document.write(eval(multiply));
Brains solution is more simple of course. But, if we change the array...
+ 10
eval(eval(eval("(function(num) { return eval(Math.sqrt(num)) })(225)")))
is it correct, guys? help
+ 8
@4rontender nope. you've forgot one eval.
+ 7
-> eval( <- eval(eval(eval("(function(num) { return eval(Math.sqrt(num)) })(225)"))) -> ) <-
+ 4
eval("equation[0]+equation[1]+ equation[2]");
might work
+ 4
Thank you all
+ 4
eval is evil