UNPKG

929 BJavaScriptView Raw
1'use strict';
2var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
3var uncurryThis = require('../internals/function-uncurry-this');
4var aCallable = require('../internals/a-callable');
5var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
6
7var aTypedArray = ArrayBufferViewCore.aTypedArray;
8var getTypedArrayConstructor = ArrayBufferViewCore.getTypedArrayConstructor;
9var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
10var sort = uncurryThis(ArrayBufferViewCore.TypedArrayPrototype.sort);
11
12// `%TypedArray%.prototype.toSorted` method
13// https://tc39.es/ecma262/#sec-%typedarray%.prototype.tosorted
14exportTypedArrayMethod('toSorted', function toSorted(compareFn) {
15 if (compareFn !== undefined) aCallable(compareFn);
16 var O = aTypedArray(this);
17 var A = arrayFromConstructorAndList(getTypedArrayConstructor(O), O);
18 return sort(A, compareFn);
19});