Elixir Check Palindrome
defmodule CheckPalindrome do
def check_palindrome(input_string), do: String.reverse(input_string) == input_string
end
This compares the string with its reverse. If they match, it is a palindrome.
Erlang Check Palindrome
-module(check_palindrome).
-export([check_palindrome/1]).
check_palindrome(InputString) ->
lists:reverse(InputString) =:= InputString.
This compares the string with its reverse. If they match, it is a palindrome.
Go Check Palindrome
func checkPalindrome(inputString string) bool {
for i, j := 0, len(inputString)-1; i < j; i, j = i+1, j-1 {
if inputString[i] != inputString[j] {
return false
}
}
return true
}
This compares the string with its reverse. If they match, it is a palindrome.
Haskell Check Palindrome
checkPalindrome :: String -> Bool
checkPalindrome inputString = reverse inputString == inputString
This compares the string with its reverse. If they match, it is a palindrome.
Java Check Palindrome
public class Solution {
public static boolean checkPalindrome(String inputString) {
return new StringBuilder(inputString).reverse().toString().equals(inputString);
}
}
This compares the string with its reverse. If they match, it is a palindrome.
Lisp Check Palindrome
(defun check-palindrome (input-string)
(string= (reverse input-string) input-string))
This compares the string with its reverse. If they match, it is a palindrome.
PHP Check Palindrome
function checkPalindrome($inputString)
{
return strrev($inputString) === $inputString;
}
This compares the string with its reverse. If they match, it is a palindrome.
Python Check Palindrome
def check_palindrome(input_string: str) -> bool:
return input_string[::-1] == input_string
This compares the string with its reverse. If they match, it is a palindrome.
Rust Check Palindrome
fn check_palindrome(input_string: &str) -> bool {
input_string.chars().rev().collect::<String>() == input_string
}
This compares the string with its reverse. If they match, it is a palindrome.
TypeScript Check Palindrome
function checkPalindrome(inputString: string): boolean {
return inputString.split("").reverse().join("") === inputString;
}
This compares the string with its reverse. If they match, it is a palindrome.