logo CodeStepByStep logo

removePalindromes

Language/Type: JavaScript arrays traversals

Write a function named removePalindromes that that removes all strings that are palindromes from an array of strings.

Your function should accept an array of strings as a parameter and replace every palindrome string it contains with an empty string, "". For example, if an array named arr stores the following element values:

let arr = ["Madam", "raceCAR", "", "hi", "A", "Abba", "banana", "dog God",
           "STOP otto POTS", "Madame", "JavaScript", "LevEL", "staTS"];

Then the call of removePalindromes(arr) should change it to contain the following element values. Notice that the palindromes from the array such as "Madam" and "LevEL" have been replaced by "".

["", "", "", "hi", "", "banana", "", "", "Madame", "JavaScript", "", ""]

You may assume that the array passed is non-null and contains only String values.

Constraints:

  • You are to modify the existing array in-place.
  • Do not create any other data structures such as temporary arrays.
  • You may create as many strings as you like, and you may use as many simple variables (such as numbers) as you like.

Note: You may want to go solve the string problem isPalindrome first and use it as part of your solution to this problem.

Type your JavaScript solution code here:


This is a function exercise. Write a JavaScript function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.