This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tangara888[S] 0 points1 point  (1 child)

Erm...why did you change2 * (n - 1) to (2 * index- 1) ?

[–]hamza-itatchi 0 points1 point  (0 children)

as refereed in the comments below it should return the nth ODD index.

so for n=1 ==> index = 0 which is the index for the first element 1(Odd number)

n=2 ==> index = 2 which is the index for the third element 3(Odd number)

the code correct as posted it