File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
lib/node_modules/@stdlib/array/fixed-endian-factory/lib Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -724,6 +724,56 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
724724 return out ;
725725 } ) ;
726726
727+ /**
728+ * Returns a new typed array containing the elements in reversed order.
729+ *
730+ * @name toReversed
731+ * @memberof TypedArray.prototype
732+ * @type {Function }
733+ * @throws {TypeError } `this` is not a typed array
734+ * @returns {TypedArray } reversed array
735+ *
736+ * @example
737+ * var Float64ArrayFE = factory( 'float64' );
738+ *
739+ * var arr = new Float64ArrayFE( 'little-endian', [1.0, 2.0, 3.0] );
740+ *
741+ * var out = arr.toReversed();
742+ * // returns <TypedArray>
743+ *
744+ * var v = out.get( 0 );
745+ * // returns 1.0
746+ *
747+ * v = out.get( 1 );
748+ * // returns 2.0
749+ *
750+ * v = out.get( 2 );
751+ * // returns 3.0
752+ */
753+ setReadOnly ( TypedArray . prototype , 'toReversed' , function toReversed ( ) {
754+ var obuf ;
755+ var out ;
756+ var len ;
757+ var buf ;
758+ var i ;
759+ var v ;
760+
761+ if ( ! isTypedArray ( this ) ) {
762+ throw new TypeError ( 'invalid invocation. `this` is not a typed array.' ) ;
763+ }
764+
765+ len = this . _length ;
766+ out = new this . constructor ( flag2byteOrder ( this . _isLE ) , len ) ;
767+ buf = this . _buffer ;
768+ obuf = out . _buffer ; // eslint-disable-line no-underscore-dangle
769+ for ( i = 0 ; i < len ; i ++ ) {
770+ v = buf [ GETTER ] ( ( ( len - 1 ) * BYTES_PER_ELEMENT ) - ( i * BYTES_PER_ELEMENT ) , this . _isLE ) ;
771+ obuf [ SETTER ] ( i * BYTES_PER_ELEMENT , v , this . _isLE ) ;
772+ }
773+
774+ return out ;
775+ } ) ;
776+
727777 /**
728778 * Sets an array element.
729779 *
You can’t perform that action at this time.
0 commit comments