我如何根据某些规则在两者之间制作一个带有空格的字符串



我正在编码一组字符串,在输出时,我想获得一个由

的空格分隔的单字符串

" imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau"

而不是

" imtgdvs"

" fearwer"

" 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);

尝试以下:

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);

相关内容

最新更新