Skip to content
Permalink
0b139d7318
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
21 lines (20 sloc) 637 Bytes
function reverseArray(array) {
let arrayNew = []
for (let index = array.length- 1; index >=0 ; index--) {
const element = array[index];
arrayNew.push(element);
}
return arrayNew
}
function reverseArrayInPlace(array) {
let lastIndex = array.length - 1
for (let index = 0; index < (lastIndex / 2); index++) {
const element = array[index];
array[index] = array[lastIndex-index]
array[lastIndex-index] = element;
}
}
console.log(reverseArray(["A", "B", "C"]));
let arrayValue = [1, 2, 3, 4, 5];
reverseArrayInPlace(arrayValue);
console.log(arrayValue);