JavaScript: Find the shortest possible string which can create a string to make it a palindrome by adding characters to the end of it
JavaScript Basic: Exercise-97 with Solution
Shortest String to Convert into Palindrome
Write a JavaScript program to find the shortest possible string. This can be converted into a string and converted into a palindrome by adding characters to the end of it.
Sample Solution:
JavaScript Code:
Output:
abcddcba 1221
Live Demo:
Flowchart:

ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that finds the shortest string which, when appended to the given string, transforms it into a palindrome.
- Write a JavaScript function that calculates the minimal suffix needed to convert a given string into a palindrome.
- Write a JavaScript program that determines and returns the shortest possible string that can be concatenated to the original string to form a palindrome.
Improve this sample solution and post your code through Disqus.
Previous: JavaScript program to compute the sum of absolute differences of consecutive numbers of a given array of integers.
Next: JavaScript program to switch case of the minimum possible number of letters to make a given string written in the upper case or in the lower case.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.