UNPKG

658 BJavaScriptView Raw
1'use strict';
2var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
3
4var aTypedArray = ArrayBufferViewCore.aTypedArray;
5var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
6var floor = Math.floor;
7
8// `%TypedArray%.prototype.reverse` method
9// https://tc39.es/ecma262/#sec-%typedarray%.prototype.reverse
10exportTypedArrayMethod('reverse', function reverse() {
11 var that = this;
12 var length = aTypedArray(that).length;
13 var middle = floor(length / 2);
14 var index = 0;
15 var value;
16 while (index < middle) {
17 value = that[index];
18 that[index++] = that[--length];
19 that[length] = value;
20 } return that;
21});