es-toolkit 1.10.1-dev.223 → 1.10.1-dev.226

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/dropRightWhile.ts"],"sourcesContent":["/**\n * Removes elements from the end of an array until the predicate returns false.\n *\n * This function iterates over an array from the end and drops elements until the provided\n * predicate function returns false. It then returns a new array with the remaining elements.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} arr - The array from which to drop elements.\n * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines\n * whether to continue dropping elements. The function is called with each element from the end,\n * and dropping continues as long as it returns true.\n * @returns {T[]} A new array with the elements remaining after the predicate returns false.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropRightWhile(array, x => x > 3);\n * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.\n */\nexport function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[] {\n for (let i = arr.length - 1; i >= 0; i--) {\n if (!canContinueDropping(arr[i])) {\n return arr.slice(0, i + 1);\n }\n }\n\n return [];\n}\n"],"mappings":";AAkBO,SAAS,eAAkB,KAAmB,qBAAgD;AACnG,WAAS,IAAI,IAAI,SAAS,GAAG,KAAK,GAAG,KAAK;AACxC,QAAI,CAAC,oBAAoB,IAAI,CAAC,CAAC,GAAG;AAChC,aAAO,IAAI,MAAM,GAAG,IAAI,CAAC;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO,CAAC;AACV;","names":[]}
@@ -191,6 +191,16 @@ function dropRight(arr, itemsCount) {
191
191
  return arr.slice(0, -itemsCount);
192
192
  }
193
193
 
194
+ // src/array/dropRightWhile.ts
195
+ function dropRightWhile(arr, canContinueDropping) {
196
+ for (let i = arr.length - 1; i >= 0; i--) {
197
+ if (!canContinueDropping(arr[i])) {
198
+ return arr.slice(0, i + 1);
199
+ }
200
+ }
201
+ return [];
202
+ }
203
+
194
204
  // src/array/dropWhile.ts
195
205
  function dropWhile(arr, canContinueDropping) {
196
206
  const dropEndIndex = arr.findIndex((item) => !canContinueDropping(item));
@@ -200,13 +210,6 @@ function dropWhile(arr, canContinueDropping) {
200
210
  return arr.slice(dropEndIndex);
201
211
  }
202
212
 
203
- // src/array/dropRightWhile.ts
204
- function dropRightWhile(arr, canContinueDropping) {
205
- const reversed = arr.slice().reverse();
206
- const dropped = dropWhile(reversed, canContinueDropping);
207
- return dropped.slice().reverse();
208
- }
209
-
210
213
  // src/array/fill.ts
211
214
  function fill(arr, value, start = 0, end = arr.length) {
212
215
  start = Math.max(start, 0);