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.
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('');
- }
Test.describe("Palindrome Tests", function(){ Test.assertEquals(Palindrome("MOM"), true); Test.assertEquals(Palindrome("kAyaK"), true); Test.assertEquals(Palindrome("123454321"), true); Test.assertEquals(Palindrome("n1oo1n"), true); Test.assertEquals(Palindrome("X"), true); Test.assertEquals(Palindrome(""), true); Test.assertEquals(Palindrome("rotlor"), false); Test.assertEquals(Palindrome("506050"), false); Test.assertEquals(Palindrome("idEddEddi"), false); });
namespace Solution {using NUnit.Framework;using System;// TODO: Replace examples and use TDD development by writing your own tests[TestFixture]public class SolutionTest{[Test]public void MyTest(){Assert.AreEqual(true, Palindrome.Check("MOM"));Assert.AreEqual(true, Palindrome.Check("kAyaK"));Assert.AreEqual(true, Palindrome.Check("123454321"));Assert.AreEqual(true, Palindrome.Check("n1oo1n"));Assert.AreEqual(true, Palindrome.Check("X"));Assert.AreEqual(true, Palindrome.Check(""));Assert.AreEqual(false, Palindrome.Check("rotlor"));Assert.AreEqual(false, Palindrome.Check("506050"));Assert.AreEqual(false, Palindrome.Check("idEddEddi"));}}}- Test.describe("Palindrome Tests", function(){
- Test.assertEquals(Palindrome("MOM"), true);
- Test.assertEquals(Palindrome("kAyaK"), true);
- Test.assertEquals(Palindrome("123454321"), true);
- Test.assertEquals(Palindrome("n1oo1n"), true);
- Test.assertEquals(Palindrome("X"), true);
- Test.assertEquals(Palindrome(""), true);
- Test.assertEquals(Palindrome("rotlor"), false);
- Test.assertEquals(Palindrome("506050"), false);
- Test.assertEquals(Palindrome("idEddEddi"), false);
- });