Created
October 7, 2022 22:57
-
-
Save Shaun289/aca195a807ccb46a46166eec705827d6 to your computer and use it in GitHub Desktop.
exercism : reverse string
This file contains hidden or 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
/// 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