Just wanting to say that all JS solutions are quite 'bad', except the simple for-of, because they're combining pure array methods (.map, .reduce) and side-effects (external variable to that method), not even talking about modifying Array protoype <a href="https://github.com/josevalim/nested-data-structure-traversal/blob/master/javascript/map_with_state.js#L3" rel="nofollow">https://github.com/josevalim/nested-data-structure-traversal...</a>, never do this, don't touch to objects you don't own, and that others would access and not expect to be modified!<p>I'll make a PR to try to contribute, instead of just complaining like that, hehe<p>Btw I'm surprised the structure isn't deeply nested (requiring recursion to process it), it'd be more interesting
Interesting how different some of the approaches are in the <i>same</i> language, never mind different languages. In clojure, the “atom” version is 5 lines (not including data or tests), while the “zipper” version is 47 lines and the “reduce” version is 31 lines
The whole problem seems to be bizarrely defined when it comes to data structures.<p>Basically the input is `data+config` merged into one object and the return value is `data+config+tranversal_properties` merged into one object with lots of solutions mutating the original input data.
What are the OP's conclusion from this experiment ?<p>I was expecting the FP languages solutions to be exceptionally short and elegant, but after a quick glance it seems to me that the Python and Python-like languages (e.g. Nim, Zig, etc.) are "winning" (YMMV of course).
Why do I see things like this and still think that XML and XSLT made a lot of this stuff very simple and portable and that we lost a good bit of progress by choosing JSON, YAML, etc after we already had great validation of schemas, translation, streaming and DOM parsing, etc.
Non-idiomatic ClojureScript, 10 lines:<p><a href="https://gist.github.com/raspasov/0521706c3f963a9209152bfb2becd91c" rel="nofollow">https://gist.github.com/raspasov/0521706c3f963a9209152bfb2be...</a><p>IMO The problem is poorly defined. Data structures should avoid control flow instructions like "reset_lesson_position"
In python/javascript, I'm a big fan of using yield - <a href="https://leontrolski.github.io/recursing-with-yield.html" rel="nofollow">https://leontrolski.github.io/recursing-with-yield.html</a><p>It just <i>feels</i> nice to me.
TIL about postfix dereference in Perl: <a href="https://perldoc.perl.org/perlref#Postfix-Dereference-Syntax" rel="nofollow">https://perldoc.perl.org/perlref#Postfix-Dereference-Syntax</a><p>One of advantages of Perl to me stable syntax - usually I can open code written by someone nowadays after not using Perl and not encounter any unknown language features. Turned out even in Perl there are new features you need to learn first before you can read the code, though compare to other languages it still easy to keep up with all new features.