hughsk / hughsk/flat

Unflatten partial arrays

Open
#130 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.8k
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Flattened arrays with indexes that don't start at 0 can't easily be unflattened.

Example:

```
const testData = {
'complexObject.1.node.id': 'my-test-id',
}

const data = unflatten(testData) as object

console.log(JSON.stringify(data))
```

The output is:

```json
{ "complexObject": [null, { "node": { "id": "my-test-id" } }] }
```

Is there a way to retrieve an unflattened version of `testData` that does not contain a "null" item? The result I'm trying to achieve is:

```json
{ "complexObject": [{ "node": { "id": "my-test-id" } }] }
```

The reason my indexes don't start at 0 is because the algorithm I'm building is filtering items in arrays, so it is expected to have non sequential indexes / indexes not starting at 0 in the initial flattened structure.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the library's unflatten entry point and reproduce the provided partial-array example. Compare the current output with the requested result, then verify the chosen behavior with a regression case covering indexes that do not start at zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.