Make a sum in thyme
Posted: Tue Oct 06, 2009 3:20 pm
for(n, (i)=>{ . . . })
How can I make a sum with the for-function?
for examlpe this simple sum
I'm asking you because for example if I type "for(10, (i)=>{i})" it just shows the 10th member:
0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 => it just shows the 10th member (the 9) as a result but not the whole sum.
So again... How can I make a sum with the for-function?
Thanks
- - - - -
I just found out how it works. If anyone needs it, here's the thyme code:
For example:
scene.my.sum(6) = 15 (because of 0 + 1 + 2 + 3 + 4 + 5)
I will extend this idea to make a general sum function so you can add everything you want.
How can I make a sum with the for-function?
for examlpe this simple sum
I'm asking you because for example if I type "for(10, (i)=>{i})" it just shows the 10th member:
0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 => it just shows the 10th member (the 9) as a result but not the whole sum.
So again... How can I make a sum with the for-function?
Thanks
- - - - -
I just found out how it works. If anyone needs it, here's the thyme code:
- Code: Select all
scene.my.sum = (n) =>
{
value := 0;
for(n, (i)=>{value = value + i});
value
}
For example:
scene.my.sum(6) = 15 (because of 0 + 1 + 2 + 3 + 4 + 5)
I will extend this idea to make a general sum function so you can add everything you want.