Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

array-with.js 758B

123456789101112131415161718
  1. 'use strict';
  2. var lengthOfArrayLike = require('../internals/length-of-array-like');
  3. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  4. var $RangeError = RangeError;
  5. // https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.with
  6. // https://tc39.es/proposal-change-array-by-copy/#sec-%typedarray%.prototype.with
  7. module.exports = function (O, C, index, value) {
  8. var len = lengthOfArrayLike(O);
  9. var relativeIndex = toIntegerOrInfinity(index);
  10. var actualIndex = relativeIndex < 0 ? len + relativeIndex : relativeIndex;
  11. if (actualIndex >= len || actualIndex < 0) throw new $RangeError('Incorrect index');
  12. var A = new C(len);
  13. var k = 0;
  14. for (; k < len; k++) A[k] = k === actualIndex ? value : O[k];
  15. return A;
  16. };