r/javaScriptStudyGroup • • May 01 '18

Can someone help me with this question? I don’t see the relation between the console log numbers and the expected output

Post image
2 Upvotes

7 comments sorted by

4

u/niallqball May 02 '18

f(1) = 0

f(2) = 0+ 1

f(3) = 0+1+2

f(4)= 0+1+2+3

f(10)= 0+1+2+3+4+5+6+7+8+9

1

u/foolishcow360 May 02 '18

Wow, thank you dude!

1

u/niallqball May 02 '18

You're welcome

2

u/mitwilsch May 02 '18

It must be using the previous numbers in some way. Any more context to the problem? Are you expected to use some math function like fibonacci or prime numbers?

1

u/foolishcow360 May 02 '18

Nope, thats all they gave me, another user solved it tho 👍

1

u/xurxo654 May 02 '18

I did it a completely different way

acc=0.5n(n-1);

1

u/foolishcow360 May 02 '18

Damn, I don’t know how you thought of that. Thanks for the answer dude!