Last active
August 20, 2023 13:35
-
-
Save clenio/2232b132da038e0d69e154f7677fa43d to your computer and use it in GitHub Desktop.
Calcula o preço médio de listagens do Mercado Livre.
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
let itens = document.querySelectorAll('.ui-search-price--size-medium .andes-visually-hidden') | |
let soma = 0 | |
itens.forEach(function(el) { | |
let cleanEl = el.innerText.replace(/ reais/g, ""); | |
return soma = soma + Number(cleanEl) | |
}) | |
const formatadorReais = new Intl.NumberFormat('pt-BR', { | |
style: 'currency', | |
currency: 'BRL' | |
}); | |
let qtd = itens.length | |
let precoMedio = soma/qtd | |
console.log(formatadorReais.format(precoMedio)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment