You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Tucsonjhall <Jh...@cactusware.com> on 2019/10/10 15:04:39 UTC
Flattening a nested array of asymetrical depth
I'm working with nested arrays of divisions in sports and need to flatten a
nested array of divisions and subdivisions to find all instances of
"division." I've been stumped how to recurse that structure so that I'm sure
I traverse all branches of the array without arbitrarily setting a limit of
how deep I will go searching for children. Suggestions on a script that
should flatten any array of objects with children?
Thanks!
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Re: Flattening a nested array of asymetrical depth
Posted by Tucsonjhall <Jh...@cactusware.com>.
Thanks Alex
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Re: Flattening a nested array of asymetrical depth
Posted by Alex Harui <ah...@adobe.com.INVALID>.
The Apache Royale Compiler will transpile your AS3 to JS for you. That's the main point of Royale. Keep your code strongly-typed so the tool chain can catch more errors sooner so there are fewer times you crash and burn.
-Alex
On 10/10/19, 9:25 AM, "Tucsonjhall" <Jh...@cactusware.com> wrote:
I appreciate it and I know I should be able to translate JS into strongly
typed AS3 but I often crash and burn because of the syntax differences. On
my todo list ;-)
--
Sent from: https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-flex-users.2333346.n4.nabble.com%2F&data=02%7C01%7Caharui%40adobe.com%7Cce2af09d0c864b13038708d74d9e73b5%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C1%7C637063215255315096&sdata=yJIVwXlSdolj7rzqWMmOCmSXCqIMhxdgGkEEv45Pbbk%3D&reserved=0
Re: Flattening a nested array of asymetrical depth
Posted by Tucsonjhall <Jh...@cactusware.com>.
Well as I suspected, my attempt to translate such symbols as => didn't go
well given my limited knowledge of JS. One important thing I left out. There
IS consistency in the naming that I forgot to mention. All the objects have
children in the form of an array named children. Does that make it any
easier?
Softball Minors (object)
children (array)
East (object)
West (object)
Softball Majors (object)
children (array)
National (object)
children (array)
East (object)
West (object)
American (object)
children (array)
East (object)
West (object)
Independent (object)
children (array)
East
children (array)
Blue
Green
West
children (array)
Orange
Yellow
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Re: Flattening a nested array of asymetrical depth
Posted by Tucsonjhall <Jh...@cactusware.com>.
Will give it a shot. Thanks much.
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Re: Flattening a nested array of asymetrical depth
Posted by kamcknig <ka...@gmail.com>.
So my example will still work though because your 'nodes' don't have
consistent naming, you'll probably have to add some data to the levels that
you want to extract into the flattened array and then where I'm checking for
"division" you would check for the new data that indicates it's at the level
you want to extract.
As for JS to AS, technically I did it in TypeScript. But it should be
directly portable aside from the types being used (just translate to as
types) and then the Array.isArray is specific to JS
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Re: Flattening a nested array of asymetrical depth
Posted by Tucsonjhall <Jh...@cactusware.com>.
I appreciate it and I know I should be able to translate JS into strongly
typed AS3 but I often crash and burn because of the syntax differences. On
my todo list ;-)
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Re: Flattening a nested array of asymetrical depth
Posted by kamcknig <ka...@gmail.com>.
Done in JS and def could be optimized. I have no idea on your data structure
or what you want the final structure to be.
https://pastebin.com/p0j2uTnp
Kyle
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/
Re: Flattening a nested array of asymetrical depth
Posted by Tucsonjhall <Jh...@cactusware.com>.
Hope the formatting of this comes out OK in post. Here's a typical structure.
Softball Minors
East
West
Softball Majors
National
East
West
American
East
West
Independent
East
Blue
Green
West
Orange
Yellow
--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/