main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
758 bytes
|
Rev | Line | |
---|
[79a0317] | 1 | 'use strict';
|
---|
| 2 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
---|
| 3 | var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
---|
| 4 |
|
---|
| 5 | var $RangeError = RangeError;
|
---|
| 6 |
|
---|
| 7 | // https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with
|
---|
| 8 | // https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with
|
---|
| 9 | module.exports = function (O, C, index, value) {
|
---|
| 10 | var len = lengthOfArrayLike(O);
|
---|
| 11 | var relativeIndex = toIntegerOrInfinity(index);
|
---|
| 12 | var actualIndex = relativeIndex < 0 ? len + relativeIndex : relativeIndex;
|
---|
| 13 | if (actualIndex >= len || actualIndex < 0) throw new $RangeError('Incorrect index');
|
---|
| 14 | var A = new C(len);
|
---|
| 15 | var k = 0;
|
---|
| 16 | for (; k < len; k++) A[k] = k === actualIndex ? value : O[k];
|
---|
| 17 | return A;
|
---|
| 18 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.