Sha256: e3f7e3b2db88ccf4d6dd5858f0a577a713d15409ee870585809cfaa53e5c27db

Contents?: true

Size: 1.19 KB

Versions: 46

Compression:

Stored size: 1.19 KB

Contents

// Taken from: https://github.com/paulmillr/es6-shim/

"use strict";

var toInteger         = require("../../../number/to-integer")
  , toPosInt          = require("../../../number/to-pos-integer")
  , validValue        = require("../../../object/valid-value")
  , objHasOwnProperty = Object.prototype.hasOwnProperty
  , max               = Math.max
  , min               = Math.min;

module.exports = function (target, start /*, end*/) {
	var arr = validValue(this)
	  , end = arguments[2]
	  , length = toPosInt(arr.length)
	  , to
	  , from
	  , fin
	  , count
	  , direction;

	target = toInteger(target);
	start = toInteger(start);
	end = end === undefined ? length : toInteger(end);

	to = target < 0 ? max(length + target, 0) : min(target, length);
	from = start < 0 ? max(length + start, 0) : min(start, length);
	fin = end < 0 ? max(length + end, 0) : min(end, length);
	count = min(fin - from, length - to);
	direction = 1;

	if (from < to && to < from + count) {
		direction = -1;
		from += count - 1;
		to += count - 1;
	}
	while (count > 0) {
		if (objHasOwnProperty.call(arr, from)) arr[to] = arr[from];
		else delete arr[from];
		from += direction;
		to += direction;
		count -= 1;
	}
	return arr;
};

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
govuk_publishing_components-17.6.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.5.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.4.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.3.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.2.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.1.1 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.1.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.0.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.29.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.28.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.27.1 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.27.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.26.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.25.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.24.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.23.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.22.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.21.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.20.1 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-16.20.0 node_modules/es5-ext/array/#/copy-within/shim.js