Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
Is there are any way to get change first and last letter in a string in JS?

I need make some width function. It take a string and must to return an arrive with changed letters. For example:

enter code here

 let word = 'letter'
 function(word) {
 // code here
 return var // {letter, etterl, tterle, terlet, erlett, rlette]
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can easily achieve the result if you first split the string, and then loop over the character array.

All you have to do is to push the first character at the end of the array on every iteration.

let word = 'letter';

function getResult(word) {
  const wordArray = word.split('');
  const result = [];
  for (let i = 0; i < word.length; ++i) {
    result.push(wordArray.join(''));
    wordArray.push(wordArray.shift());
  }

  return result;
}

console.log(getResult(word));

about 4 years ago · Juan Pablo Isaza Relatório

0

you can do this:

function permut(string) {
  if (string.length < 2) return string;

  const permutations = [];
  for (let i = 0; i < string.length; i++) {
    const char = string[i];

    if (string.indexOf(char) !== i) continue;

    const remainingString =
      string.slice(0, i) + string.slice(i + 1, string.length);

    for (const subPermutation of permut(remainingString))
      permutations.push(char + subPermutation);
  }
  return permutations;
}

console.log(permut("hello"));

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda