'use strict';

// MODULES //

var isArray = require( '@stdlib/utils/is-array' );
var isTypedArrayLike = require( '@stdlib/utils/is-typed-array-like' );
var isInteger = require( '@stdlib/utils/is-integer' );
var pushArray = require( './push_array.js' );
var pushObject = require( './push_object.js' );
var pushTypedArray = require( './push_typed_array.js' );


// MAIN //

/**
* Adds one or more elements to the end of a collection.
*
* @param {(Array|TypedArray|Object)} collection - collection
* @param {...*} items - items to add
* @throws {TypeError} must provide either an Array, Typed Array, or an array-like Object
* @returns {(Array|TypedArray|Object)} updated collection
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
*
* arr = push( arr, 6.0, 7.0 );
* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
*
* @example
* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
*
* arr = push( arr, 6.0, 7.0 )
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
*/
function push( collection ) {
	var items;
	var i;
	items = new Array( arguments.length-1 );
	for ( i = 0; i < arguments.length-1; i++ ) {
		items[ i ] = arguments[ i+1 ];
	}
	if ( isArray( collection ) ) {
		return pushArray( collection, items );
	}
	// Check for a typed-array-like object, as verifying actual typed arrays is expensive...
	if ( isTypedArrayLike( collection ) ) {
		return pushTypedArray( collection, items );
	}
	// Check for an array-like object...
	if (
		collection !== null &&
		typeof collection === 'object' &&
		typeof collection.length === 'number' &&
		isInteger( collection.length ) &&
		collection.length >= 0
	) {
		return pushObject( collection, items );
	}
	throw new TypeError( 'invalid input argument. First argument must be either an Array, Typed Array, or an array-like Object. Value: `'+collection+'`.' );
} // end FUNCTION push()


// EXPORTS //

module.exports = push;

'use strict';

// MODULES //

var isArray = require( '@stdlib/utils/is-array' );
var isTypedArrayLike = require( '@stdlib/utils/is-typed-array-like' );
var isInteger = require( '@stdlib/utils/is-integer' );
var pushArray = require( './push_array.js' );
var pushObject = require( './push_object.js' );
var pushTypedArray = require( './push_typed_array.js' );


// MAIN //

/**
* Adds one or more elements to the end of a collection.
*
* @param {(Array|TypedArray|Object)} collection - collection
* @param {...*} items - items to add
* @throws {TypeError} must provide either an array, typed array, or an array-like object
* @returns {(Array|TypedArray|Object)} updated collection
*
* @example
* var arr = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
*
* arr = push( arr, 6.0, 7.0 );
* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
*
* @example
* var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
*
* arr = push( arr, 6.0, 7.0 )
* // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
*/
function push( collection ) {
	var items;
	var i;
	items = new Array( arguments.length-1 );
	for ( i = 0; i < arguments.length-1; i++ ) {
		items[ i ] = arguments[ i+1 ];
	}
	if ( isArray( collection ) ) {
		return pushArray( collection, items );
	}
	// Check for a typed-array-like object, as verifying actual typed arrays is expensive...
	if ( isTypedArrayLike( collection ) ) {
		return pushTypedArray( collection, items );
	}
	// Check for an array-like object...
	if (
		collection !== null &&
		typeof collection === 'object' &&
		typeof collection.length === 'number' &&
		isInteger( collection.length ) &&
		collection.length >= 0
	) {
		return pushObject( collection, items );
	}
	throw new TypeError( 'invalid input argument. First argument must be either an Array, Typed Array, or an array-like Object. Value: `'+collection+'`.' );
} // end FUNCTION push()


// EXPORTS //

module.exports = push;

Update description