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

264
Vistas
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 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