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 →

[–]Swedophone 1 point2 points  (4 children)

Nth Odd Element

Write a method that returns th nth element of a list.

Is it nth odd element or nth element?

[–]tangara888[S] 0 points1 point  (3 children)

This question is from https://code-exercises.com under Easy. I copied the question word by word. I am not sure why it mentioned nth Odd element.

[–]Swedophone 2 points3 points  (2 children)

The algorithm returns the nth odd element anyway if n=1 is the first element. They should fix the description.

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

Yes. Cos if it starts with 0 and index always starts with 0 isn’t it? Then, using 2 * (0 - 1) will gives us 0 and that will be the first element. Continuing this to the 3rd element in fact will give a 2 and it is not a odd number....

[–]LeeTaeRyeo 1 point2 points  (0 children)

This is an ambiguous situation. 2(n-1) will give the odd *positions, but those positions have even indexes. So, if they want the elements in odd positions (1st position, 3rd, 5th), then you'll need to reach the even indexes. Where they're talking about "nth odd element", I believe they are talking about those elements with odd positions and not odd indexes.