November 28th, 2024
What's missing in this code?
minStepsToPalindrome('abca'); // Output: 3 (abca + cba)
minStepsToPalindrome('racecar'); // Output: 0 (already palindrome)
minStepsToPalindrome('mada'); // Output: 1 (mada + m)
minStepsToPalindrome('hello'); // Output: 4
minStepsToPalindrome('mirror'); // Output: 5
function minStepsToPalindrome(str) {
function isPalindrome(s) {
return s === s.split('').
.join('');
}
let count = 0;
(!isPalindrome(str)) {
str = str.slice(
);
count++;
}
return count;
}
Type or select from these options