@polgubau/utils
Version:
A collection of utility functions for TypeScript
1 lines • 1.29 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/arrays/arrayUtils.ts"],"sourcesContent":["/**\n * Returns the first element of an array\n * @param arr\n * @returns the first element of the array\n * @example first([1, 2, 3]) // 1\n */\nexport function first<T>(arr: T[]): T | undefined {\n return arr[0];\n}\n\n/**\n * Returns the last element of an array\n * @param arr\n * @returns the last element of the array\n * @example last([1, 2, 3]) // 3\n */\nexport function last<T>(arr: T[]): T | undefined {\n return arr[arr.length - 1];\n}\n\n\n/**\n * Removes the first element of an array\n * @param arr\n * @returns a new array without the first element\n * @example removeFirst([1, 2, 3]) // [2, 3]\n */\nexport function removeFirst<T>(arr: T[]): T[] {\n return arr.slice(1);\n}\n\n/**\n * Removes the last element of an array\n * @param arr\n * @returns a new array without the last element\n * @example removeLast([1, 2, 3]) // [1, 2]\n */\nexport function removeLast<T>(arr: T[]): T[] {\n return arr.slice(0, arr.length - 1);\n}\n\n\n"],"mappings":";AAMO,SAAS,MAAS,KAAyB;AAChD,SAAO,IAAI,CAAC;AACd;AAQO,SAAS,KAAQ,KAAyB;AAC/C,SAAO,IAAI,IAAI,SAAS,CAAC;AAC3B;AASO,SAAS,YAAe,KAAe;AAC5C,SAAO,IAAI,MAAM,CAAC;AACpB;AAQO,SAAS,WAAc,KAAe;AAC3C,SAAO,IAAI,MAAM,GAAG,IAAI,SAAS,CAAC;AACpC;","names":[]}