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

270
Visualizações
How to create palindrome number from random integer

How to create a palindrome number from a random positive integer using a centred number palindrome?

When int S=244; return 424   
When int S=12231; return 12321   
When int S=2233; return 232  //drop 3 to make palindrome number
When int S=123432; return 23432   //drop 1 to make palindrome number
When int S=0000; return 0
//starting and ending with 0 is not a proper palindrome number in this code. e.g. 010, 02320 is not a palindrome number

I was thinking about making an array of the random positive integer then store the palindrome number in another array and finally return the palindrome integer

function solution(int S){ //S=1144 -> 141, so I need to drop 4...
 const num=S;
 const array=Array.from(String(num), Number); //array=[1,1,4,4]
 const palinArray=[];
 var palinNum=0;

 //if num is already palindrome number
 cost rev=array.reverse();  //rev=[4,4,1,1]
 if(array===rev){
   palinNum=Number(array.join(''));
   return plainNum;
 }

 //if num is not palindrome, check if num can transform to a palindrome
 for(var i=0;i<array.length-1;i++){
   for(var k=i;k<array.length;k++){
   //I thought if switching array[i] integer to the array[i+1] interger makes entire number palindrome, switch it and move i+2 for next loop but makes no sense.  
   }
 }//end for loop
//console.log(palinNum);
}

So I think I still did not fully understand but I want to return the palindrome number of this solution function.

about 4 years ago · Juan Pablo Isaza
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