Skip to main content
added 71 characters in body
Source Link
Sky
  • 2.4k
  • 2
  • 8
  • 26

There are number of syntax issues in the code you posted. But this should help;

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

contract RevertArray {

    function reverseArray(uint[] memory arr1array) public pure returns(uint[] memory) {

    uint length =  arr1array.length;
    uint numberOfElements = length -1;
    uint[] memory arr2reversed = new uint[](length);
    
    uint i = length - 1;numberOfElements;
    uint j = 0;j;

    while( j < length - 1numberOfElements) {
        arr2[j]reversed[j] = arr1[i];array[i];    
        i--;
        j++;
    } 

    arr2[j]reversed[j] = arr1[i];array[i];

    return arr2;reversed;

    }

}

There are number of syntax issues in the code you posted. But this should help;

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

contract RevertArray {

    function reverseArray(uint[] memory arr1) public pure returns(uint[] memory) {

    uint length =  arr1.length;
    uint[] memory arr2 = new uint[](length);
    
    uint i = length - 1;
    uint j = 0;

    while( j < length - 1) {
        arr2[j] = arr1[i];    
        i--;
        j++;
    } 

    arr2[j] = arr1[i];

    return arr2;

    }

}

There are number of syntax issues in the code you posted. But this should help;

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

contract RevertArray {

    function reverseArray(uint[] memory array) public pure returns(uint[] memory) {

    uint length = array.length;
    uint numberOfElements = length -1;
    uint[] memory reversed = new uint[](length);
    
    uint i = numberOfElements;
    uint j;

    while( j < numberOfElements) {
        reversed[j] = array[i];    
        i--;
        j++;
    } 

    reversed[j] = array[i];

    return reversed;

    }

}
Source Link
Sky
  • 2.4k
  • 2
  • 8
  • 26

There are number of syntax issues in the code you posted. But this should help;

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;

contract RevertArray {

    function reverseArray(uint[] memory arr1) public pure returns(uint[] memory) {

    uint length =  arr1.length;
    uint[] memory arr2 = new uint[](length);
    
    uint i = length - 1;
    uint j = 0;

    while( j < length - 1) {
        arr2[j] = arr1[i];    
        i--;
        j++;
    } 

    arr2[j] = arr1[i];

    return arr2;

    }

}