From a774e1eedc5b84519b0147609b25222d44705af7 Mon Sep 17 00:00:00 2001 From: Renan Fernandes Date: Wed, 29 Jun 2022 14:24:08 -0300 Subject: [PATCH] =?UTF-8?q?mentoria=20de=20revis=C3=A3o=20turma=2023?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Destructuring e HOFs/desafio-hofs-01.js | 8 ++++++- .../Destructuring e HOFs/desafio-hofs-02.js | 23 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Desafios/Destructuring e HOFs/desafio-hofs-01.js b/Desafios/Destructuring e HOFs/desafio-hofs-01.js index 20bfd07..1fbecb3 100644 --- a/Desafios/Destructuring e HOFs/desafio-hofs-01.js +++ b/Desafios/Destructuring e HOFs/desafio-hofs-01.js @@ -2,8 +2,14 @@ const data = require('./data'); /** 1 - Retorne e exiba um array com as informações da primeira e da segunda banda utilizando destructuring */ -const getBandsInformation = () => { +// console.log(data.bands); +const getBandsInformation = ({ bands }) => { + const [ primeiraBanda, segundaBanda ] = bands; // estamos armazenando apenas as duas primeiras bandas do array + return [ primeiraBanda, segundaBanda ]; // criando um novo array contendo apenas as duas bandas } +// para ver todos os objetos em detalhes, usar o JSON.stringify(objeto) +console.log(getBandsInformation(data)); + module.exports = getBandsInformation; diff --git a/Desafios/Destructuring e HOFs/desafio-hofs-02.js b/Desafios/Destructuring e HOFs/desafio-hofs-02.js index b6de7f0..1a3be8e 100644 --- a/Desafios/Destructuring e HOFs/desafio-hofs-02.js +++ b/Desafios/Destructuring e HOFs/desafio-hofs-02.js @@ -4,9 +4,30 @@ const data = require('./data'); retornando uma string no seguinte formato: "os melhores álbuns do Radiohead: In Rainbows,Kid A,OK Computer,Pablo Honey" */ -const getBestAlbuns = () => { +const getBestAlbuns = (bands) => { + const [ primeiraBanda ] = bands; + const { bandName, bestAlbuns } = primeiraBanda; + const albumNames = bestAlbuns.map((bestAlbum) => { + return bestAlbum.name; + }); + + const stringAlbumNames = albumNames.join(',') + + return `os melhores álbuns do ${bandName}: ${stringAlbumNames}`; } +// const getBestAlbuns = ([ primeiraBanda ]) => { +// const { bandName, bestAlbuns } = primeiraBanda; + +// const albumNames = bestAlbuns.map(({ name }) => name); + +// const stringAlbumNames = albumNames.join(',') + +// return `os melhores álbuns do ${bandName}: ${stringAlbumNames}`; +// } + +console.log(getBestAlbuns(data.bands)); + module.exports = getBestAlbuns;