+ 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);

4th Mar 2018, 7:26 PM
Ole113
Ole113 - avatar
9 Réponses
4th Mar 2018, 7:47 PM
MecyDev
MecyDev - avatar
+ 11
but it works😳 silent, where I forgot one eval?
5th Mar 2018, 2:31 AM
\__(° = °)__/
+ 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...
4th Mar 2018, 7:40 PM
MecyDev
MecyDev - avatar
+ 10
eval(eval(eval("(function(num) { return eval(Math.sqrt(num)) })(225)"))) is it correct, guys? help
4th Mar 2018, 7:43 PM
\__(° = °)__/
+ 8
@4rontender nope. you've forgot one eval.
4th Mar 2018, 8:27 PM
Vladislav Tikhiy (SILENT)
Vladislav Tikhiy (SILENT) - avatar
+ 7
-> eval( <- eval(eval(eval("(function(num) { return eval(Math.sqrt(num)) })(225)"))) -> ) <-
5th Mar 2018, 5:49 AM
Vladislav Tikhiy (SILENT)
Vladislav Tikhiy (SILENT) - avatar
+ 4
eval("equation[0]+equation[1]+ equation[2]"); might work
4th Mar 2018, 7:34 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 4
Thank you all
4th Mar 2018, 8:16 PM
Ole113
Ole113 - avatar
+ 4
eval is evil
7th Mar 2018, 7:15 AM
Chat d'Oeuf (Baron)
Chat d'Oeuf (Baron) - avatar