Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda