Ad

Palindrome without case sensitivity in Javascript

Since there is no built in string reverse, solution is to turn it into an array, use the built in array reverse, and join it back together.

Code
Diff
  • function Palindrome(str){
      // Case insensitive palindrome
      str = str.toUpperCase();
      return str == str.split('').reverse().join('');
    }
    • using System.Linq;
    • class Palindrome
    • {
    • public static bool Check(string word) {
    • var upper = word.ToUpperInvariant();
    • return upper.SequenceEqual(upper.Reverse());
    • }
    • function Palindrome(str){
    • // Case insensitive palindrome
    • str = str.toUpperCase();
    • return str == str.split('').reverse().join('');
    • }