Design a site like this with WordPress.com
Get started

Can my word be a Palindrome?

A palindrome is a number, sentence or word that reads the same forward and backward. Even a DNA structure can be a palindrome. It has significance in various branches of higher research.

Word examples: madam, bob
Numerical examples: 101, 191
Date & Time examples: 12:21, 11/11/1111, 12/12/2121
Sentence example: Rats live on no evil star

Although mostly numbers are tested to be palindrome, here we shall test if a given sentence or word is Palindrome.

Steps:
1. Using a function to take an input to test
2. Making the input lowercase
3. Reversing the input
4. Comparing the reversed input with the original lowercase input

Palindrome program in Swift language:

import Foundation

// function to check if the input is a Palindrome
func palindromeTest(_ inputString : String) -> Bool{
// making the input lowercase
let lowercasedInput = inputString.lowercased()
/* comparison of the reversed with the original will return True if it is a palindrome */
return lowercasedInput.reversed() == Array(lowercasedInput)
}

// Any word or sentence can be passed from here to check print(palindromeTest(“Quran”))

Output:

Advertisement

Published by Farial Mahmod Tishan

Life-long learner. Developing Flutter apps on Parrot Linux OS .

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: