All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2601_2700.s2649_nested_array_generator.solution.ts Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
// #Medium #2023_09_06_Time_138_ms_(86.92%)_Space_74.9_MB_(73.36%)

type MultidimensionalArray = (MultidimensionalArray | number)[]

function* inorderTraversal(arr: MultidimensionalArray): Generator {
    for (const item of arr)
        if (Array.isArray(item)) yield* inorderTraversal(item)
        else yield item
}

/*
 * const gen = inorderTraversal([1, [2, 3]]);
 * gen.next().value; // 1
 * gen.next().value; // 2
 * gen.next().value; // 3
 */

export { inorderTraversal }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy