var x = ["a", "b", "c"];
for(var i = 0; i < x.length; i++){
x[i] = x[2 - i];
}
My approach:
for i = 0 => x[0] = x[2] (which is "c", so replace "a" with "c")
for i = 1 => x[1] = x[1] (which is "b", so replace "b" with "b")
for i = 2 => x[2] = x[0] (which is "a" so replace "c" with "a")
for i = 3 test failed, stop.
so x = ["c", "b", "a"]
Why does the console return x as ["c","b","c"]? Could somebody please tell me whether I have completely misunderstood loop logic? Thank you!
x.reverse()?