mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(core): simplify array flatten logic (#48358)
We can now use modern Javascript to get the same result. PR Close #48358
This commit is contained in:
parent
7c4e9ce5c0
commit
eae182da84
3 changed files with 2 additions and 22 deletions
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {flatten} from '../util/array_utils';
|
||||
import {EMPTY_ARRAY} from '../util/empty';
|
||||
import {stringify} from '../util/stringify';
|
||||
|
||||
|
|
|
|||
|
|
@ -32,27 +32,11 @@ export function arrayEquals<T>(a: T[], b: T[], identityAccessor?: (value: T) =>
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flattens an array.
|
||||
*/
|
||||
export function flatten(list: any[], dst?: any[]): any[] {
|
||||
if (dst === undefined) dst = list;
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
let item = list[i];
|
||||
if (Array.isArray(item)) {
|
||||
// we need to inline it.
|
||||
if (dst === list) {
|
||||
// Our assumption that the list was already flat was wrong and
|
||||
// we need to clone flat since we need to write to it.
|
||||
dst = list.slice(0, i);
|
||||
}
|
||||
flatten(item, dst);
|
||||
} else if (dst !== list) {
|
||||
dst.push(item);
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
export function flatten(list: any[]): any[] {
|
||||
return list.flat(Number.POSITIVE_INFINITY);
|
||||
}
|
||||
|
||||
export function deepForEach<T>(input: (T|any[])[], fn: (value: T) => void): void {
|
||||
|
|
|
|||
|
|
@ -1019,9 +1019,6 @@
|
|||
{
|
||||
"name": "first"
|
||||
},
|
||||
{
|
||||
"name": "flatten"
|
||||
},
|
||||
{
|
||||
"name": "flatten2"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue