Code Lab

Modo entrevista. Cronômetro de 3 min, sem dicas e sem autocompletar

JSON there and back

FácilJSON and data3 min

Write a function jsonRoundTrip(user). It turns the object user into a JSON string and then parses that string back into a new object. Return { json, copy } with the string and the object made from it.

Exemplos

jsonRoundTrip({ name: 'John', age: 35 })

Retorna { json: '{"name":"John","age":35}', copy: { name: 'John', age: 35 } }

The JSON string has no spaces, and the keys are in double quotes.

Fonte

Carregando o editor...
  1. EntradajsonRoundTrip({ name: 'John', age: 35 })
    Esperado{ json: '{"name":"John","age":35}', copy: { name: 'John', age: 35 } }
  2. copy equals user, but it is a different object

Os testes ocultos rodam no envio