Skip to content

Instantly share code, notes, and snippets.

@ZhangSen1
Created June 29, 2016 07:00
Show Gist options
  • Save ZhangSen1/f3442defbcaf1157e73d64e56f8fa192 to your computer and use it in GitHub Desktop.
Save ZhangSen1/f3442defbcaf1157e73d64e56f8fa192 to your computer and use it in GitHub Desktop.
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