Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!