remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 2.51 kB
Source Map (JSON)
{"version":3,"file":"dropLastWhile.cjs","names":["purry"],"sources":["../src/dropLastWhile.ts"],"sourcesContent":["import type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport { purry } from \"./purry\";\n\n/**\n * Removes elements from the end of the array until the predicate returns false.\n *\n * The predicate is applied to each element in the array starting from the end and moving towards the beginning, until the predicate returns false. The returned array includes elements from the beginning of the array, up to and including the element that produced false for the predicate.\n *\n * @param data - The array.\n * @param predicate - The predicate.\n * @signature\n * R.dropLastWhile(data, predicate)\n * @example\n * R.dropLastWhile([1, 2, 10, 3, 4], x => x < 10) // => [1, 2, 10]\n * @dataFirst\n * @category Array\n */\nexport function dropLastWhile<T extends IterableContainer>(\n data: T,\n predicate: (item: T[number], index: number, data: T) => boolean,\n): Array<T[number]>;\n\n/**\n * Removes elements from the end of the array until the predicate returns false.\n *\n * The predicate is applied to each element in the array starting from the end and moving towards the beginning, until the predicate returns false. The returned array includes elements from the beginning of the array, up to and including the element that produced false for the predicate.\n *\n * @param predicate - The predicate.\n * @signature\n * R.dropLastWhile(predicate)(data)\n * @example\n * R.pipe([1, 2, 10, 3, 4], R.dropLastWhile(x => x < 10)) // => [1, 2, 10]\n * @dataLast\n * @category Array\n */\nexport function dropLastWhile<T extends IterableContainer>(\n predicate: (item: T[number], index: number, data: T) => boolean,\n): (data: T) => Array<T[number]>;\n\nexport function dropLastWhile(...args: ReadonlyArray<unknown>): unknown {\n return purry(dropLastWhileImplementation, args);\n}\n\nfunction dropLastWhileImplementation<T extends IterableContainer>(\n data: T,\n predicate: (item: T[number], index: number, data: T) => boolean,\n): Array<T[number]> {\n for (let i = data.length - 1; i >= 0; i--) {\n if (!predicate(data[i], i, data)) {\n return data.slice(0, i + 1);\n }\n }\n return [];\n}\n"],"mappings":"wCAuCA,SAAgB,EAAc,GAAG,EAAuC,CACtE,OAAOA,EAAAA,EAAM,EAA6B,EAAK,CAGjD,SAAS,EACP,EACA,EACkB,CAClB,IAAK,IAAI,EAAI,EAAK,OAAS,EAAG,GAAK,EAAG,IACpC,GAAI,CAAC,EAAU,EAAK,GAAI,EAAG,EAAK,CAC9B,OAAO,EAAK,MAAM,EAAG,EAAI,EAAE,CAG/B,MAAO,EAAE"}