@polgubau/utils
Version:
A collection of utility functions for TypeScript
1 lines • 1.02 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/arrays/remove.ts"],"sourcesContent":["/**\n * Removes the element at the specified index from the array.\n * This modifies the original array.\n * @param arr - The array from which to remove the element.\n * @param index - The index of the element to remove.\n * @returns The modified array with the element removed.\n * @example remove([1, 2, 3], 1) // [1, 3]\n */\nexport function remove<T>(arr: T[], index: number): T[] {\n // Adjust the index if it's negative\n const adjustedIndex = index < 0 ? arr.length + index : index;\n\n // If the adjusted index is out of bounds, return the original array\n if (adjustedIndex < 0 || adjustedIndex >= arr.length) {\n return arr;\n }\n\n // Remove the element at the specified index\n arr.splice(adjustedIndex, 1);\n return arr;\n}\n"],"mappings":";AAQO,SAAS,OAAU,KAAU,OAAoB;AAEtD,QAAM,gBAAgB,QAAQ,IAAI,IAAI,SAAS,QAAQ;AAGvD,MAAI,gBAAgB,KAAK,iBAAiB,IAAI,QAAQ;AACpD,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,eAAe,CAAC;AAC3B,SAAO;AACT;","names":[]}