Palindrome String

Problem

A string that is the same when read from the front or read from the back is called a palindrome.
When a string is input, write a program that outputs “YES” if the string is a palindrome string, and “NO” if it is not a palindrome string.
However, it is not case sensitive when checking palindromes.

input

The first line is given a non-blank string with an integer length of 100 or less.

gooG

output

The first line outputs the result of whether it is a palindrome string as YES or NO.

YES

Solution

using reverse()

function solution(s) {
	let answer = 'YES';
	let lower = s.toLowerCase();
	let reverse = s.toLowerCase().split('').reverse().join('');
	if (lower !== reverse) answer = 'NO';

	return answer;
}

not using reverse()

function solution(s) {
	let answer = 'YES';
	s = s.toLowerCase();
	let len = s.length;
	for (let i = 0; i < Math.floor(len / 2); i++) {
		if (s[i] !== s[len - i - 1]) return 'No';
	}
	return answer;
}