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

126
Visualizações
How to do string divided into letters then push into the next letter?
let output ="I am a string"

const app=output.split("")

console.log(app)

//output (13) [ "I", " ", "a", "m", " ", "a", " ", "s", "t", "r", "i", "n", "g" ]

then it need to change per letter into the next one in alphabetically

which means

"j","","b","n","","b,","","t","u","s","j","o","h"

after that the string must be written like ; "jbnbtusjoh"

any opinion?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Ok, so lets do this step by step:

// first the string
let out = "I am a string"
// convert to array 
let arOut = out.split("") // gives ["I"," ", "a", "m", " ", "a"....]
// now lets get cracking : 

let mapped = arOut.map(element => element == ' ' ? element : String.fromCharCode(element.charCodeAt(0)+1))
// this get char code of element and then adds one and gets equivalent char ignores space

let newOut = mapped.join("") // we have our result

console.log(newOut)

about 4 years ago · Juan Pablo Isaza Relatório

0

After splitting, map the array of characters, convert each one to code (if not a space), add one, and convert the code back to a char:

const output = 'I am a string'

const result = output.split('')
  .map(c => c === ' ' 
    ? c // ignore spaces
    : String.fromCharCode(c.charCodeAt(0) + 1) // convert char to code, add one, and convert back to char
  )
  .join('') // if you need a string

console.log(result)

You can also use Array.from() to directly convert the string to an array of the transformed characters:

const output = 'I am a string'

const result = Array.from(
  output,
  c => c === ' ' ? c : String.fromCharCode(c.charCodeAt(0) + 1)
).join('')

console.log(result)

about 4 years ago · Juan Pablo Isaza Relatório

0

Why not convert each char into ASCII and then simply increment the number?

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