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:
Alan Agius 2022-12-05 16:18:26 +00:00 committed by Andrew Kushnir
parent 7c4e9ce5c0
commit eae182da84
3 changed files with 2 additions and 22 deletions

View file

@ -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';

View file

@ -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 {

View file

@ -1019,9 +1019,6 @@
{
"name": "first"
},
{
"name": "flatten"
},
{
"name": "flatten2"
},