-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(drop): support array-like args (#686)
* fix(drop): support arrary-like args * doc * Update dropWhile.ts * Update dropRightWhile.ts --------- Co-authored-by: Sojin Park <[email protected]>
- Loading branch information
Showing
18 changed files
with
210 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { dropRight as dropRightToolkit } from '../../array/dropRight.ts'; | ||
import { isArrayLike } from '../predicate/isArrayLike.ts'; | ||
|
||
/** | ||
* Removes a specified number of elements from the end of an array and returns the rest. | ||
* | ||
* This function takes an array and a number, and returns a new array with the specified number | ||
* of elements removed from the end. | ||
* | ||
* @template T - The type of elements in the array. | ||
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements. | ||
* @param {number} itemsCount - The number of elements to drop from the end of the array. | ||
* @returns {T[]} A new array with the specified number of elements removed from the end. | ||
* | ||
* @example | ||
* const array = [1, 2, 3, 4, 5]; | ||
* const result = dropRight(array, 2); | ||
* // result will be [1, 2, 3] since the last two elements are dropped. | ||
*/ | ||
export function dropRight<T>(collection: ArrayLike<T> | null | undefined, itemsCount: number): T[] { | ||
if (!isArrayLike(collection)) { | ||
return []; | ||
} | ||
|
||
return dropRightToolkit(Array.from(collection), itemsCount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.