Rust
pub fn xo (value: &str) -> bool { let value = value.to_lowercase(); let count_x = value.matches("x").count(); let count_o = value.matches("o").count(); count_x == count_o } #[cfg(test)] mod tests { use super::*; #[test] fn test_1() { assert_eq!(xo("ooxx"), true); } #[test] fn test_2() { assert_eq!(xo("xooxx"), false); } #[test] fn test_3() { assert_eq!(xo("ooxXm"), true); } #[test] fn test_4() { assert_eq!(xo("zzoo"), false); } #[test] fn test_5() { assert_eq!(xo("zpzpzpp"), true); } }
Rust Playground GitHub Gist
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Rust
Rust Playground
GitHub Gist