[해결로 표시] 팔린드롬 - JavaScript의 대칭 확인

  

3
주제 스타터

Write a JS function (program) that checks if an input string is a palindrome. See what is a palindrome: https://en.wikipedia.org/wiki/Palindrome

The input comes as a single string argument.

예시:

입력: haha

출력: false


입력: racecar

출력: true


입력: unitinu

출력: true

The output is the return value of your function. It should be true if the string is a palindrome and false if it’s not.

1개 답글
2

Here is my palindrome:

/**
 *
 * @param str {string}
 * @returns {boolean}
 */
 
function isPalindrome(str) {
    for (let i = 0; i < str.length / 2; i++) {
        if (str[i] != str[str.length - i - 1]) {
            return false;
        }
    }
    return true;
}
 
console.log(isPalindrome("abba"));
공유: