How to use Iterative Approach In JavaScript
Example:
function isSymmetric(str) {
let left = 0;
let right = str.length - 1;
while (left < right) {
if (str[left] !== str[right]) {
return false;
}
left++;
right--;
}
return true;
}
let inputStr = "abcdcba";
if (isSymmetric(inputStr)) {
console.log("The given string is Symmetric");
} else {
console.log("The given string is Not Symmetric");
}
Output
The given string is Symmetric
JavaScript Program to Check Whether the String is Symmetrical or Not
In this article, we will see how to check whether the given string is symmetric or not. The symmetrical string is one that is similar from the starting to mid and mid to end.
Example:
Input: khokho Output: The entered string is symmetrical Input: madam Output: The entered string is not symmetrical Input:amaama Output: The entered string is symmetrical
Contact Us