15 lines
340 B
Rust
15 lines
340 B
Rust
pub fn is_palindrome(string: String) -> bool {
|
|
let normalized = string.chars().filter_map(|c| {
|
|
if char::is_alphanumeric(c) {
|
|
Some(c.to_ascii_lowercase())
|
|
} else {
|
|
None
|
|
}
|
|
});
|
|
|
|
let regular = normalized.clone().collect::<String>();
|
|
let reversed = normalized.rev().collect::<String>();
|
|
|
|
regular == reversed
|
|
}
|