Skip to content

Instantly share code, notes, and snippets.

@KerryRitter
Created July 6, 2016 18:49
Show Gist options
  • Save KerryRitter/59f67a1e9a0f5172326fea1c9d7608ab to your computer and use it in GitHub Desktop.
Save KerryRitter/59f67a1e9a0f5172326fea1c9d7608ab to your computer and use it in GitHub Desktop.
Array safe replace for when Angular isn't kind
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