我正在编码一组字符串,在输出时,我想得到一个由空格分隔的单个字符串
“ imtgdvs恐惧者mayoogo anouuio ntnnlvt wttddes aohghn ssauau”
代替
“ imtgdvs”
“恐惧者”
“ mayoogo”
“ anouuio”
“ ntnnlvt”
“ wttddes”
“ aohghn”
“ sseoau”
normalisedText = "ifmanwasmeanttostayonthegroundgodwouldhavegivenusroots";
const cols = Math.ceil(Math.sqrt(textCount));
const rows = Math.ceil(textCount / cols);
const textArray = [];
let encodedChunks = "";
let cypherText = "";
let startIndex = 0;
for (let i = 0; i < cols; i ++) {
for (let j = i; j < normalisedText.length; j += cols) {
cypherText += normalisedText[j];
}
cypherText += '\n';
}
console.log(cypherText);
答案 0 :(得分:0)
尝试一下:
textCount = 5
normalisedText = "ifmanwasmeanttostayonthegroundgodwouldhavegivenusroots";
const cols = Math.ceil(Math.sqrt(textCount));
const rows = Math.ceil(textCount / cols);
const textArray = [];
let encodedChunks = "";
let cypherText = "";
let startIndex = 0;
for (let i = 0; i < cols; i ++) {
for (let j = i; j < normalisedText.length; j += cols) {
cypherText += normalisedText[j];
}
cypherText += ' ';
}
console.log(cypherText);