this is a simple function:
function sequence(a,b,c,d){
var x = 0;
var y = 0;
for(var i = a; i<=b; i++){
y = eval(c);
x = eval(d);
}
return x;
}
a&b must be an integer and c&d must be a string
this code gets the sum of 1 to 5:
sequence(1,5,"i","x+y")
result:
15
this code gets the product of 1 to 5:
sequence(1,5,"i","x*y")
result:
0
the problem is at “var x = 0;
“, the value of “x
” should be how many?
sequence(1,5,"i","x+y") >>> 15
sequence(1,5,"i","x*y") >>> 0
sequence(1,5,"i","x-y") >>> -15
sequence(1,5,"i","x/y") >>> 0
sequence(1,5,"i","x**y") >>> 0
sequence(1,5,"i","x%y") >>> 0