Skip to content

Instantly share code, notes, and snippets.

@gisderdube
Created December 25, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gisderdube/ba2b4b72d50f82c88afa1cf540caefa8 to your computer and use it in GitHub Desktop.
Save gisderdube/ba2b4b72d50f82c88afa1cf540caefa8 to your computer and use it in GitHub Desktop.
import axios from 'axios'
let myData = [{id: 0}, {id: 1}, {id: 2}, {id: 3}]
async function fetchData(dataSet) {
const pokemonPromises = dataSet.map(entry => {
return axios.get(`https://ironhack-pokeapi.herokuapp.com/pokemon/${entry.id}`)
})
const results = await Promise.all(pokemonPromises)
results.forEach(result => {
updateData(result.data)
})
console.log(myData)
}
function updateData(newData) {
myData = myData.map(el => {
if(el.id === newData.id) return newData
return el
})
}
fetchData(myData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment