How to check for a given word malyalam is palindrome or not.
Here is a sample program how to create a program for word malayalam to check if it is palindrome or not.
This is interview question for experienced developers
import React, { useState } from 'react';
const PalindromeChecker = () => {
const [input, setInput] = useState('');
const [result, setResult] = useState('');
const handleChange = (event) => {
setInput(event.target.value);
};
const checkForPalindrome = () => {
const word = input.toLowerCase().replace(/[^\u0D00-\u0D7F]/g, '');
const reversedWordString = word.split('').reverse().join('');
setResult(word === reversedWordString ? 'It is a palindrome' : 'It is not a palindrome');
};
return (
<div>
<textarea value={input} onChange={handleChange} />
<button onClick={checkForPalindrome}>Check Palindrome</button>
<p>{result}</p>
</div>
);
};
export default PalindromeChecker;
Write this program and try to execute it .
Comments
Post a Comment