-
-
Save parzibyte/f782c64f5362bd91c50b61a9c563309c to your computer and use it in GitHub Desktop.
This file contains 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
const separarCadenaEnArregloSiSuperaLongitud = (cadena, maximaLongitud) => { | |
const resultado = []; | |
let indice = 0; | |
while (indice < cadena.length) { | |
const pedazo = cadena.substring(indice, indice + maximaLongitud); | |
indice += maximaLongitud; | |
resultado.push(pedazo); | |
} | |
return resultado; | |
} | |
const dividirCadenasYEncontrarMayorConteoDeBloques = (contenidosConMaximaLongitud) => { | |
let mayorConteoDeCadenasSeparadas = 0; | |
const cadenasSeparadas = []; | |
for (const contenido of contenidosConMaximaLongitud) { | |
const separadas = separarCadenaEnArregloSiSuperaLongitud(contenido.contenido, contenido.maximaLongitud); | |
cadenasSeparadas.push({ separadas, maximaLongitud: contenido.maximaLongitud }); | |
if (separadas.length > mayorConteoDeCadenasSeparadas) { | |
mayorConteoDeCadenasSeparadas = separadas.length; | |
} | |
} | |
return [cadenasSeparadas, mayorConteoDeCadenasSeparadas]; | |
} | |
const tabularDatos = (cadenas, relleno, separadorColumnas) => { | |
const [arreglosDeContenidosConMaximaLongitudSeparadas, mayorConteoDeBloques] = dividirCadenasYEncontrarMayorConteoDeBloques(cadenas) | |
let indice = 0; | |
const lineas = []; | |
while (indice < mayorConteoDeBloques) { | |
let linea = ""; | |
for (const contenidos of arreglosDeContenidosConMaximaLongitudSeparadas) { | |
let cadena = ""; | |
if (indice < contenidos.separadas.length) { | |
cadena = contenidos.separadas[indice]; | |
} | |
if (cadena.length < contenidos.maximaLongitud) { | |
cadena = cadena + relleno.repeat(contenidos.maximaLongitud - cadena.length); | |
} | |
linea += cadena + separadorColumnas; | |
} | |
lineas.push(linea); | |
indice++; | |
} | |
return lineas; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment