Created
November 5, 2020 20:49
-
-
Save lomholdt/10d178fc0b5fea355a1468ca09722436 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let result = is_palindrome("racecar"); // Should be true | |
println!("{}", result); | |
} | |
fn is_palindrome(name: &str) -> bool { | |
let half = name.len() / 2; | |
name | |
.bytes() | |
.take(half) | |
.eq(name | |
.bytes() | |
.rev() | |
.take(half)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment