function printInReverse(list) { Let 'len' equal to length of 'elements' Let 'i' equal to len - 1 While 'i' is equal or greater than 0 Let 'nextElement' equal to the element in 'elements' at index 'i' println 'nextElement' Let 'i' equal to 'i' minus 1 }
function printInReverse(elements) {
let len = elements.length
let i = len - 1;
while (i >= 0) {
let nextElem = elements[i]
println(nextElem)
i = i - 1
}
}
//try-it
let list = [10, 20, 30, 40];
printInReverse(list);
let len = elements.length
let i = len - 1
while (i >= 0) {
while (i < elements.length) {
let nextElem = elements[i]
println(nextElement.toString())
i = i + 1
}
elements = [Riya, Asha, Chin]
[Riya, Asha, Chin] printInReverse(elements) {
3 let len = elements.length 2 3 let i = len - 1
2 while (i >= 0) { Chin 2 let nextElem = elements[i] Chin println(nextElement.toString()) 1 2 i = i - 1 }
1 while (i >= 0) { Asha 1 let nextElem = elements[i] Asha println(nextElement.toString()) 0 1 i = i - 1 }
0 while (i >= 0) { Riya 0 let nextElem = elements[i] Riya println(nextElement.toString()) -1 0 i = i - 1 }
-1
while (i >= 0) {