lodash-move
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -19,4 +19,14 @@ "use strict"; | ||
*/ | ||
var itemRemovedArray = [].concat(_toConsumableArray(array.slice(0, moveIndex)), _toConsumableArray(array.slice(moveIndex + 1, array.length))); | ||
return [].concat(_toConsumableArray(itemRemovedArray.slice(0, toIndex)), [array[moveIndex]], _toConsumableArray(itemRemovedArray.slice(toIndex, itemRemovedArray.length))); | ||
var item = array[moveIndex]; | ||
var length = array.length; | ||
var diff = moveIndex - toIndex; | ||
if (diff > 0) { | ||
// move left | ||
return [].concat(_toConsumableArray(array.slice(0, toIndex)), [item], _toConsumableArray(array.slice(toIndex, moveIndex)), _toConsumableArray(array.slice(moveIndex + 1, length))); | ||
} else if (diff < 0) { | ||
// move right | ||
return [].concat(_toConsumableArray(array.slice(0, moveIndex)), _toConsumableArray(array.slice(moveIndex + 1, toIndex + 1)), [item], _toConsumableArray(array.slice(toIndex + 1, length))); | ||
} | ||
return array; | ||
} |
{ | ||
"name": "lodash-move", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "DRY up your common use cases in Redux.", | ||
@@ -19,3 +19,3 @@ "repository": "https://github.com/granteagon/move", | ||
"babel-cli": "^6.9.0", | ||
"eslint": "^2.11.1", | ||
"eslint": "^2.2.0", | ||
"expect": "^1.20.1", | ||
@@ -30,3 +30,2 @@ "babel-core": "^5.4.7", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"eslint": "^2.2.0", | ||
"mocha": "^2.4.5", | ||
@@ -33,0 +32,0 @@ "nodemon": "^1.9.1", |
# _.move LoDash mixin | ||
Move an item in an array | ||
`npm install lodash-move` | ||
LoDash issue is [here](https://github.com/lodash/lodash/issues/1978). Give it a 👍 if you want to see it added to Lodash. | ||
@@ -5,0 +7,0 @@ |
@@ -12,11 +12,24 @@ export default function move (array, moveIndex, toIndex) { | ||
*/ | ||
let itemRemovedArray = [ | ||
...array.slice(0, moveIndex), | ||
...array.slice(moveIndex + 1, array.length) | ||
] | ||
return [ | ||
...itemRemovedArray.slice(0, toIndex), | ||
array[moveIndex], | ||
...itemRemovedArray.slice(toIndex, itemRemovedArray.length) | ||
] | ||
let item = array[moveIndex]; | ||
let length = array.length; | ||
let diff = moveIndex - toIndex; | ||
if (diff > 0) { | ||
// move left | ||
return [ | ||
...array.slice(0, toIndex), | ||
item, | ||
...array.slice(toIndex, moveIndex), | ||
...array.slice(moveIndex + 1, length) | ||
]; | ||
} else if (diff < 0) { | ||
// move right | ||
return [ | ||
...array.slice(0, moveIndex), | ||
...array.slice(moveIndex + 1, toIndex + 1), | ||
item, | ||
...array.slice(toIndex + 1, length) | ||
]; | ||
} | ||
return array; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10401
104
16