Created
July 6, 2016 18:49
-
-
Save KerryRitter/59f67a1e9a0f5172326fea1c9d7608ab to your computer and use it in GitHub Desktop.
Array safe replace for when Angular isn't kind
This file contains 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
declare module _ { | |
interface LoDashStatic { | |
arraySafeReplace: (existingArray: any[], newArray: any[]) => any[]; | |
} | |
} | |
_.mixin({ "arraySafeReplace": (existingArray: any[], newArray: any[]) => { | |
if (existingArray) { | |
existingArray.length = 0; | |
} else { | |
existingArray = []; | |
} | |
Array.prototype.push.apply(existingArray, newArray); | |
return existingArray; | |
}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment