Skip to content

Add flatten-array - #104

Merged
glennj merged 3 commits into
exercism:mainfrom
glennj:flatten-array
Mar 19, 2026
Merged

Add flatten-array#104
glennj merged 3 commits into
exercism:mainfrom
glennj:flatten-array

Conversation

@glennj

@glennj glennj commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

No description provided.

-- `ipairs` stops at the first index gap. Seems to me, the
-- easiest way to render an arbitrary list of lists is to
-- stringify it back into JSON, and then munge the string.
-- Unfortunately, we seem to lose _trailing_ nulls this way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json.decode has three parameters per https://dkolf.de/dkjson-lua/documentation. The third one lets us specify a replacement value besides the default nil for nulls in the JSON. The page documents a json.null for setting an explicit null value. In bin/generate-spec, we use canonical_data = json.decode read_file canonical_data_path, but we could instead use canonical_data = json.decode (read_file canonical_data_path), 1, json.null. That'll keep the trailing nulls in place although we'd still need to represent them as "null" in the final tables.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@glennj

glennj commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

Since I'm changing the generate_spec script, I'll follow up with a PR that regenerates all specs.

@glennj
glennj merged commit be9c977 into exercism:main Mar 19, 2026
3 checks passed
@glennj
glennj deleted the flatten-array branch March 19, 2026 20:37
@BNAndras BNAndras added x:rep/large Large amount of reputation x:module/practice-exercise Work on Practice Exercises labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

x:module/practice-exercise Work on Practice Exercises x:rep/large Large amount of reputation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants