Modo entrevista. Cronômetro de 4 min, sem dicas e sem autocompletar
Field from a response
FácilJSON and data4 min
A test got the body of an API response as a JSON string. The product is in the field data.product. Write a function getProduct(body) that returns an object with only the name and price of that product.
Exemplos
getProduct('{"status":200,"data":{"product":{"id":7,"name":"Phone","price":300}}}')Retorna { name: 'Phone', price: 300 }
Carregando o editor...
- Entrada
getProduct('{"status":200,"data":{"product":{"id":7,"name":"Phone","price":300}}}')Esperado{ name: 'Phone', price: 300 } - Entrada
getProduct('{"status":200,"data":{"product":{"id":12,"name":"Laptop","price":1500,"stock":4}}}')Esperado{ name: 'Laptop', price: 1500 }
Os testes ocultos rodam no envio