Last active
November 17, 2017 12:11
-
-
Save codeepic/3020233e01f01b30a62e16d013d0f785 to your computer and use it in GitHub Desktop.
The FunctionalUtil class holds functional JavaScript helper methods.
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
export class FunctionalUtil{ | |
static removeItem<T>(arr: T[], index: number): T[]{ | |
return [ | |
...arr.slice(0, index), | |
...arr.slice(index + 1) | |
]; | |
} | |
static replaceItem<T>(arr: T[], item: T, index: number): T[]{ | |
return[ | |
...arr.slice(0, index), | |
item, | |
...arr.slice(index +1) | |
]; | |
} | |
static addItem<T>(arr: T[], item: T): T[]{ | |
return [...arr, item]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment