remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 1.47 kB
Source Map (JSON)
{"version":3,"file":"dropLast.cjs","names":["purry"],"sources":["../src/dropLast.ts"],"sourcesContent":["import type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport { purry } from \"./purry\";\n\n/**\n * Removes last `n` elements from the `array`.\n *\n * @param array - The target array.\n * @param n - The number of elements to skip.\n * @signature\n * R.dropLast(array, n)\n * @example\n * R.dropLast([1, 2, 3, 4, 5], 2) // => [1, 2, 3]\n * @dataFirst\n * @category Array\n */\nexport function dropLast<T extends IterableContainer>(\n array: T,\n n: number,\n): Array<T[number]>;\n\n/**\n * Removes last `n` elements from the `array`.\n *\n * @param n - The number of elements to skip.\n * @signature\n * R.dropLast(n)(array)\n * @example\n * R.dropLast(2)([1, 2, 3, 4, 5]) // => [1, 2, 3]\n * @dataLast\n * @category Array\n */\nexport function dropLast(\n n: number,\n): <T extends IterableContainer>(array: T) => Array<T[number]>;\n\nexport function dropLast(...args: ReadonlyArray<unknown>): unknown {\n return purry(dropLastImplementation, args);\n}\n\nconst dropLastImplementation = <T extends IterableContainer>(\n array: T,\n n: number,\n): Array<T[number]> =>\n n > 0 ? array.slice(0, Math.max(0, array.length - n)) : [...array];\n"],"mappings":"wCAmCA,SAAgB,EAAS,GAAG,EAAuC,CACjE,OAAOA,EAAAA,EAAM,EAAwB,EAAK,CAG5C,MAAM,GACJ,EACA,IAEA,EAAI,EAAI,EAAM,MAAM,EAAG,KAAK,IAAI,EAAG,EAAM,OAAS,EAAE,CAAC,CAAG,CAAC,GAAG,EAAM"}