]> git.r.bdr.sh - rbdr/dotfiles/blob
c0bfb8b0609f4e9ac8df6c11dff5e88bdcfc8739
[rbdr/dotfiles] /
1 // Taken from: https://github.com/paulmillr/es6-shim/
2
3 'use strict';
4
5 var toInteger = require('../../../number/to-integer')
6 , toPosInt = require('../../../number/to-pos-integer')
7 , validValue = require('../../../object/valid-value')
8
9 , hasOwnProperty = Object.prototype.hasOwnProperty
10 , max = Math.max, min = Math.min;
11
12 module.exports = function (target, start/*, end*/) {
13 var o = validValue(this), end = arguments[2], l = toPosInt(o.length)
14 , to, from, fin, count, direction;
15
16 target = toInteger(target);
17 start = toInteger(start);
18 end = (end === undefined) ? l : toInteger(end);
19
20 to = target < 0 ? max(l + target, 0) : min(target, l);
21 from = start < 0 ? max(l + start, 0) : min(start, l);
22 fin = end < 0 ? max(l + end, 0) : min(end, l);
23 count = min(fin - from, l - to);
24 direction = 1;
25
26 if ((from < to) && (to < (from + count))) {
27 direction = -1;
28 from += count - 1;
29 to += count - 1;
30 }
31 while (count > 0) {
32 if (hasOwnProperty.call(o, from)) o[to] = o[from];
33 else delete o[from];
34 from += direction;
35 to += direction;
36 count -= 1;
37 }
38 return o;
39 };