Created
June 8, 2021 02:40
-
-
Save Gabirel/60b1bc25051a25cb1f2a4af65cd9fe13 to your computer and use it in GitHub Desktop.
Merge Strings Alternately in Rust
This file contains 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
use itertools::Itertools; | |
fn main() { | |
assert_eq!( | |
"a1b2c3def", | |
merge_alternately_itertools("abcdef".to_string(), "123".to_string()) | |
); | |
assert_eq!( | |
"a1b2c3456", | |
merge_alternately_itertools("abc".to_string(), "123456".to_string()) | |
); | |
} | |
// I know I can simplify code below but I insist this. | |
pub fn merge_alternately_itertools(word1: String, word2: String) -> String { | |
let mut ans = String::new(); | |
ans = word1.chars().interleave(word2.chars()).collect(); | |
ans | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment