Created
March 20, 2025 21:48
-
-
Save codermapuche/c53b7d9181663e675527241f0cc3ecf4 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
"use strict"; | |
// ---------------------------------------------------------------------------- | |
const fs = require('fs'); | |
// ---------------------------------------------------------------------------- | |
const INPUT = 'palabrasRI.txt', | |
CRLF = '\n'; | |
// ---------------------------------------------------------------------------- | |
let inputs = fs.readFileSync(INPUT, 'utf8'); | |
inputs = inputs.split(CRLF); | |
inputs = inputs.reduce((acc, w) => { | |
if ( !acc.hasOwnProperty(w) ) { | |
acc[w] = { w, c: 0 }; | |
} | |
acc[w].c++; | |
return acc; | |
}, { }); | |
inputs = Object.values(inputs); | |
inputs.sort((a, b) => (a.c - b.c)); | |
console.log('Cantidad de palabras únicas', inputs.length); | |
if ( inputs.length > 0 ) { | |
console.log('Cantidad de veces que aparece cada palabra', inputs); | |
console.log('Palabra menos frecuente', inputs[0].w); | |
console.log('Palabra más frecuente', inputs[inputs.length - 1].w); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment