Last active
February 20, 2021 19:10
-
-
Save fernandodof/8604b452dcde6b66888f7690b38b60ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getPricesLastDays(days) { | |
try { | |
const result = await fetch(`https://api.gold/price?days=${days}`); | |
const prices = await result.json(); | |
const sum = prices.reduce((total, currentValue) => total + currentValue, 0); | |
const average = sum / prices.length; | |
return { average: +average.toFixed(2) }; | |
} catch (error) { | |
// handle error | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment