Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Test-a-function/Rust/test-a-function.rust
Normal file
25
Task/Test-a-function/Rust/test-a-function.rust
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/// Tests if the given string slice is a palindrome (with the respect to
|
||||
/// codepoints, not graphemes).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use playground::palindrome::is_palindrome;
|
||||
/// assert!(is_palindrome("abba"));
|
||||
/// assert!(!is_palindrome("baa"));
|
||||
/// ```
|
||||
pub fn is_palindrome(s: &str) -> bool {
|
||||
let half = s.len();
|
||||
s.chars().take(half).eq(s.chars().rev().take(half))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::is_palindrome;
|
||||
|
||||
#[test]
|
||||
fn test_is_palindrome() {
|
||||
assert!(is_palindrome("abba"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue