This log is a complete reading of a journal inspired by the original: Evil eval and New Function.
We rarely use the new array to define an array, and I don't think that the new array has such a magical magic that we can create n empty elements with the new array (n), and there are n-1 blanks in the middle of n elements, and by join, We can put something in these blanks to make up the special strings that we need, which inspires me that I can easily implement a "continuous operation of regular elements" without a loop. For example, to calculate the number of 1-100. In the past we needed to loop from 1 to 100 and then sum, but with this feature of the array we could do it with a simple line of code, as follows:
Copy Code code as follows:
var i=0,sum=eval (' 0 ' +new Array (). Join (' + (++i) '));
In addition, you can do many similar mathematical operations, such as the following
Copy Code code as follows:
Eval (' 0 ' +new Array (one). Join (' +math.pow (++i,2) ')//compute 1-10 squared sum
Eval (' 0 ' +new Array (100/2). Join (' + (i+=2) ')//COMPUTE 2+4+6+ ... 100 of and
These we have in the past through the loop of the calculation, now can be a line of code cleverly done, have to admire the implicit programming language dexterity, programming the world there are always too many things waiting for us to find.
To change the above JavaScript code to a VBS, is the so-called "Ashes-level solution" of the VBS exercises:
Copy Code code as follows:
Dim A (101)
Execute (Join (A, "s=s+i:i=i+1:"))
MsgBox s
Original: http://demon.tw/programming/no-loop-calculate-1-100-sum.html