-4
I’m trying to do a function that reads a txt file and returns the number of vowels in the file.
const fs = require('fs');
let texto = "Teste";//tem 2 vogais
fs.writeFile("teste.txt",texto ,(err)=>{
if(err) {
throw err;
}
console.log("Arquivo salvo");
});
function vogal (file) {
const letras = ["a", "e", "i", "o", "u"];
var cont = 1;
fs.readFile(file, (err, data) =>{
if(err) throw err;
data.toString().split("").forEach(itemTexto =>{
letras.forEach(itemLetra=>{
if(itemTexto === itemLetra) cont++;
});
});
});
return cont;//retorna 1
}
console.log(vogal("teste.txt"));
Return consonant size only?
– Maury Developer
You are counting the vowels, it will only give the right value if there is a very large coincidence in the text. Learn more at this link: https://escolakids.uol.com.br/portugues/consoantes.htm (commented by Maury)
– Bacco
@Bacco copying my comment? I did not offend the author of the message. I put that because I was confused.
– Maury Developer
@Maurydeveloper as it was removed, I did not want to lose its relevant link and replenished.
– Bacco
No problem. Who removed....
– Maury Developer
I apologize for the mistake, I ended up getting confused with the names, but the goal is to count the vowels. I will edit the question to be clearer.
– Carlos Storari