toReversed

Return a new array with elements in reverse order.

Usage

var toReversed = require( '@stdlib/array/base/to-reversed' );

toReversed( x )

Returns a new array with elements in reverse order.

var x = [ 1, 2, 3, 4, 5, 6 ];

var out = toReversed( x );
// returns [ 6, 5, 4, 3, 2, 1 ]

var bool = ( out === x );
// returns false

Notes

  • If provided an array-like object having a toReversed method, the function defers execution to that method and assumes that the method API has the following signature:

    x.toReversed()
    
  • If provided an array-like object without a toReversed method, the function manually reverses elements and copies to a new generic array.

Examples

var zeroTo = require( '@stdlib/array/base/zero-to' );
var toReversed = require( '@stdlib/array/base/to-reversed' );

var x = zeroTo( 6 );
// returns [ 0, 1, 2, 3, 4, 5 ]

var y = toReversed( x );
// returns [ 5, 4, 3, 2, 1, 0 ]

var z = toReversed( y );
// returns [ 0, 1, 2, 3, 4, 5 ]
Did you find this page helpful?