UNPKG

958 BJavaScriptView Raw
1'use strict';
2var $ = require('../internals/export');
3var uncurryThis = require('../internals/function-uncurry-this');
4var aCallable = require('../internals/a-callable');
5var toIndexedObject = require('../internals/to-indexed-object');
6var arrayFromConstructorAndList = require('../internals/array-from-constructor-and-list');
7var getBuiltInPrototypeMethod = require('../internals/get-built-in-prototype-method');
8var addToUnscopables = require('../internals/add-to-unscopables');
9
10var $Array = Array;
11var sort = uncurryThis(getBuiltInPrototypeMethod('Array', 'sort'));
12
13// `Array.prototype.toSorted` method
14// https://tc39.es/ecma262/#sec-array.prototype.tosorted
15$({ target: 'Array', proto: true }, {
16 toSorted: function toSorted(compareFn) {
17 if (compareFn !== undefined) aCallable(compareFn);
18 var O = toIndexedObject(this);
19 var A = arrayFromConstructorAndList($Array, O);
20 return sort(A, compareFn);
21 }
22});
23
24addToUnscopables('toSorted');