Usando o método reverso para reverter uma matriz
var arr = [1,2,3,4];
arr.reverse();
console.log(arr);
Outrageous Ostrich
var arr = [1,2,3,4];
arr.reverse();
console.log(arr);
#include <iostream>
#include <iomanip>
using namespace std;
void reverseArray(int array[],int newArray[],int size);
void printArray (int array[],int size);
int main()
{
int list [6],newList[6];
for(int i=0;i<6;i++){
cout<<"Element "<<i<<": ";
cin>>list[i];
}
reverseArray(list,newList,6);
cout<<"Original array: \n";
printArray (list,6);
cout<<endl<<"Reversed array: \n";
printArray (newList,6);
}
void reverseArray(int array[],int newArray[],int size){
for(int i=0,j=size-1;i<size;i++,j--)
newArray[j]=array[i];
}
void printArray (int array[],int size){
for(int i=0;i<size;i++)
cout<<setw(5)<<array[i];
}
var arrayReverse = ["s", "o", "f", "t", "h", "u", "n", "t"]. reverse ();
["t", "n", "u", "h", "t", "f", "o", "s"]
let mainFunction=(arr)=>{
if(arr.length %2 != 0 ){
return false
}
else{
for (let i=0 ; i < arr.length /2 ; ++i ){
let temp=arr[i];
arr[i]=arr[i + arr.length /2]
arr[i+ arr.length /2]= temp
}
}
return arr
}
console.log(mainFunction([1,2,4,6]))
//output
// [4,6,1,2]