Executando verificação de segurança...
1

É um teste simples, porém relevante, ele vai avaliar seu raciocionio lógico, organização do código, nomes das variáveis, quais abordagens vai utilizar, legibilidade de código e até mesmo como você encara o problema, sendo um teste automático acho que ele não é muito relevante mas se for um teste numa entrevista com alguém de verdade serve de ótimo filtro, resolvendo ou não o problema dentro do tempo proposto disertar sobre o problema e como você chegou ou tentou chegar a solução seria uma baita filtro pra entender se de fato o candidato atende o nível de senioridade que a vaga exige, segue a solução que eu faria para o problema

/**
 * @function formatStringToGoesAndComesFormat
 * @param {string} word
 * @param {number} numberOfRows
 */
function formatStringToGoesAndComesFormat(word, numberOfRows) {
  const wordLength = word.length;
  const numberOfCols = Math.trunc(wordLength / numberOfRows);
  const remainingLettersQuantity = wordLength % numberOfRows;
  const partOfTheWordWithoutTheRemainingLetters = word
    .split('')
    .slice(0, wordLength - remainingLettersQuantity);

  const remainingLettersOfTheWord = word
    .split('')
    .splice(remainingLettersQuantity * -1, remainingLettersQuantity);

  const formattedLettersArray = new Array(numberOfRows)
    .fill(0)
    .flatMap((_, index) => {
      const initialIndex = index * numberOfCols;
      const finalIndex = index * numberOfCols + numberOfCols;
      const lettersArray = partOfTheWordWithoutTheRemainingLetters.slice(
        initialIndex,
        finalIndex
      );
      return index % 2 === 0 ? lettersArray : lettersArray.reverse();
    });

  remainingLettersOfTheWord.forEach((letter, index) => {
    if (index % 2 === 0) {
      formattedLettersArray.unshift(letter);
      return;
    }

    formattedLettersArray.push(letter);
  });

  return formattedLettersArray.join('');
}

console.table({
  value: formatStringToGoesAndComesFormat('SEMSOBRAS', 3),
  expected: 'SEMBOSRAS',
  result: formatStringToGoesAndComesFormat('SEMSOBRAS', 3) === 'SEMBOSRAS',
});
console.table({
  value: formatStringToGoesAndComesFormat('HELLOWISECODE', 3),
  expected: 'EHELLSIWOECOD',
  result:
    formatStringToGoesAndComesFormat('HELLOWISECODE', 3) === 'EHELLSIWOECOD',
});
console.table({
  value: formatStringToGoesAndComesFormat('STRINGCOMSOBRAFOUR', 5),
  expected: 'ROSTRGNICOMBOSRAFU',
  result:
    formatStringToGoesAndComesFormat('STRINGCOMSOBRAFOUR', 5) ===
    'ROSTRGNICOMBOSRAFU',
});
Carregando publicação patrocinada...