Created
June 29, 2016 07:00
-
-
Save ZhangSen1/f3442defbcaf1157e73d64e56f8fa192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getNewArrayByMoveElement = function( array, insertIndex, predicate ) { | |
var tmpDeepCopyArray; | |
try { | |
tmpDeepCopyArray = array.slice( 0 ); | |
var tmpIndex = _.findLastIndex( tmpDeepCopyArray, predicate ); | |
var removedElements = tmpDeepCopyArray.splice( tmpIndex, 1 ); | |
if ( removedElements.length > 0 ) { | |
tmpDeepCopyArray.splice( insertIndex, 0, removedElements[ 0 ] ); | |
} | |
} catch ( e ) { | |
tmpDeepCopyArray = array.slice( 0 ); | |
console.log(e); | |
} | |
return tmpDeepCopyArray; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment