Skip to content

Instantly share code, notes, and snippets.

@Gabirel
Created June 8, 2021 02:40
Show Gist options
  • Save Gabirel/60b1bc25051a25cb1f2a4af65cd9fe13 to your computer and use it in GitHub Desktop.
Save Gabirel/60b1bc25051a25cb1f2a4af65cd9fe13 to your computer and use it in GitHub Desktop.
Merge Strings Alternately in Rust
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