Skip to content

Commit

Permalink
chore: deprecate flat (#165)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Larson <[email protected]>
  • Loading branch information
MarlonPassos-git and aleclarson authored Aug 16, 2024
1 parent d6e0dff commit d1bc75a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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()
}

0 comments on commit d1bc75a

Please sign in to comment.