Skip to content

Instantly share code, notes, and snippets.

@codeepic
Last active November 17, 2017 12:11
Show Gist options
  • Save codeepic/3020233e01f01b30a62e16d013d0f785 to your computer and use it in GitHub Desktop.
Save codeepic/3020233e01f01b30a62e16d013d0f785 to your computer and use it in GitHub Desktop.
The FunctionalUtil class holds functional JavaScript helper methods.
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