Skip to content

Commit

Permalink
feat(@redux-eggs/core): refactor flat-util
Browse files Browse the repository at this point in the history
  • Loading branch information
fostyfost committed Nov 11, 2021
1 parent cb68599 commit be6d766
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/core/src/flat/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import type { Egg, EggTuple } from '@/contracts'

const isArray = Array.isArray

export const flat = (tuple: EggTuple): Egg[] => {
const result: Egg[] = []

const flat = (tuple: EggTuple): void => {
const flatten = (tuple: EggTuple): void => {
tuple.forEach(item => {
if (Array.isArray(item)) {
flat(item)
if (isArray(item)) {
flatten(item)
} else {
result.push(item)
}
})
}

if (Array.isArray(tuple)) {
flat(tuple)
if (isArray(tuple)) {
flatten(tuple)
}

return result
Expand Down

0 comments on commit be6d766

Please sign in to comment.