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-18.0.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.21.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.20.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.19.1 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.19.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.18.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.17.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.16.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.15.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.14.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.13.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.12.2 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.12.1 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.12.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.11.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.10.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.9.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.8.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.7.0 node_modules/es5-ext/array/#/copy-within/shim.js
govuk_publishing_components-17.6.1 node_modules/es5-ext/array/#/copy-within/shim.js