30-seconds-of-code: js - unflattenObject: fails to correctly restore nested properties

Created on 5 Aug 2020  路  7Comments  路  Source: 30-seconds/30-seconds-of-code

The unflattenObject function works fine with the provided example

unflattenObject({ 'a.b.c': 1, d: 1 }); // { a: { b: { c: 1 } }, d: 1 }

But it won't work as expected on { 'a.b': 1, 'a.c': 2, d: 3 }, returns an object with a.b. missing.
It also throws on nested values that are not numbers like { 'a.b': 'foo', d: 3 }, results in Unexpected token in JSON.

See https://runkit.com/tbasse/5f2a9929c9b5c9001a4d3a6e for some tests

bug

All 7 comments

I'll like to take a look at this issue.

@Sparkadelic177 Sure, go ahead! :ok_hand:

Hum..

@pachbrasil you can go for it if you want.

sure

@Sparkadelic177 can I please take this?

@Chalarangelo I have opened a pull request for this.
Thankyou !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fuchao2012 picture fuchao2012  路  4Comments

YusofBandar picture YusofBandar  路  5Comments

Chalarangelo picture Chalarangelo  路  5Comments

Priyansh2001here picture Priyansh2001here  路  5Comments

Chalarangelo picture Chalarangelo  路  5Comments