Created
September 8, 2019 22:28
-
-
Save sassman/30c0afc5865529a5e9c7a1c0a6aea1ac to your computer and use it in GitHub Desktop.
rust tdd: src/lib.rs
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
// src/lib.rs | |
pub fn alphabet_position(s: &str) -> String { | |
s.chars() // <-- get an iterator over all chars | |
.map(|x| -> u8 { x as u8 - 'a' as u8 + 1 }) // <-- substract the ascii value of 'a' | |
.map(|x| -> String { x.to_string() }) // <-- convert the char to a String | |
.collect::<Vec<String>>() // <-- collect a Vector of String | |
.join(" ") // <-- join the Strings by whitespace | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment