Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecate flat #165

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/array/flat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ title: flat
description: Flatten an array of arrays into a single dimension
---

:::caution[Deprecated]
This function is deprecated. Use `Array.prototype.flat` instead, which is widely available and supports both deep and shallow flattening.

[MDN: Array.prototype.flat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
:::

### Usage

Given an array that contains many arrays, return a new array where all items from the children are present at the top level.
Expand Down
7 changes: 3 additions & 4 deletions src/array/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Given an array of arrays, returns a single dimensional array with
* all items in it.
*
* @deprecated Use [Array.prototype.flat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) instead.
*
* @see https://radashi-org.github.io/reference/array/flat
* @example
* ```ts
Expand All @@ -10,8 +12,5 @@
* ```
*/
export function flat<T>(lists: readonly T[][]): T[] {
return lists.reduce((acc, list) => {
acc.push(...list)
return acc
}, [])
return lists.flat()
}
Loading