Skip to content

Commit 599113d

Browse files
committed
refactor: simplify flatten function using Array.prototype.flat
1 parent 29abd17 commit 599113d

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

src/utils/array.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,7 @@ export function flatten (array) {
472472
// if not an array, return as is
473473
return array
474474
}
475-
const flat = []
476-
477-
array.forEach(function callback (value) {
478-
if (Array.isArray(value)) {
479-
value.forEach(callback) // traverse through sub-arrays recursively
480-
} else {
481-
flat.push(value)
482-
}
483-
})
484-
485-
return flat
475+
return array.flat(Infinity)
486476
}
487477

488478
/**

0 commit comments

Comments
 (0)