Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Created October 7, 2022 22:57
Show Gist options
  • Save Shaun289/aca195a807ccb46a46166eec705827d6 to your computer and use it in GitHub Desktop.
Save Shaun289/aca195a807ccb46a46166eec705827d6 to your computer and use it in GitHub Desktop.
exercism : reverse string
/// https://exercism.org/tracks/rust/exercises/reverse-string/iterations?idx=1
/// 함수형으로 쉽게 할 수 있으나 문제 의도에 맞춰 iteration으로 만듬
/// 기초적인 언어 문제를 다시 생각할 수 있게 되서 좋았음
pub fn reverse(input: &str) -> String {
//input.chars().rev().collect()
let len = input.len();
let mut s = String::with_capacity(input.len());
for c in input.chars().rev() {
s.push(c);
}
s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment