Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 7daysofrain/32b0a2d6bfeaa8e7d91341710a6430c9 to your computer and use it in GitHub Desktop.
Save 7daysofrain/32b0a2d6bfeaa8e7d91341710a6430c9 to your computer and use it in GitHub Desktop.
temperaturas
const lat = 36.527061;
const lng = -6.288596;
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m`;
function mostrar(tiempo) {
//console.log(tiempo.current.temperature_2m)
//console.log(tiempo.hourly.time[68])
//console.log(tiempo.hourly.temperature_2m[68])
calcularTemperaturaMedia(tiempo, 0);
}
function calcularTemperaturaMedia(tiempo, dia) {
let temperaturas = tiempo.hourly.temperature_2m;
temperaturas = temperaturas.filter( (temp, index) => {
if(index >= (dia * 24) && index < ((dia+1) * 24)) {
return true;
} else {
return false;
}
})
let media = 0;
temperaturas.forEach( temp => {
media += temp;
})
console.log(media/24)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment