Created
December 18, 2020 01:22
-
-
Save fauxsaurus/83367f4e0bb7094a7c6fa25570a4aed4 to your computer and use it in GitHub Desktop.
Array Utils
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
// note: the existing item needs to appear after so that this can put stuff at the start of the array | |
// note: if an i > length is used, it will just be added to the last place | |
const insertAt = <T>(arr: T[], i:number, item: T) => | |
arr.slice(0, i).concat([item]).concat(arr.slice(i)); // prettier-ignore | |
const removeAt = <T>(arr: T[], i: number) => | |
arr.slice(0, i).concat(arr.slice(i + 1)) // prettier-ignore | |
const setAt = <T>(arr: T[], i: number, item: T) => | |
arr.slice(0, i).concat([item]).concat(arr.slice(i + 1)); // prettier-ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment