DEV Community

Discussion on: Daily Challenge #47 - Alphabets

Collapse
 
brightone profile image
Oleksii Filonenko • Edited

Rust:

pub fn alphabet_position(text: &str) -> String {
    text.to_lowercase()
        .chars()
        .filter(|c| c.is_alphabetic())
        .map(|char| (char as usize - 96).to_string())
        .collect::<Vec<String>>()
        .join(" ")
}

#[test]                                                                                        
fn test_alphabet_position() {                                                                  
    assert_eq!(                                                                                
        alphabet_position("The sunset sets at twelve o' clock."),                              
        String::from("20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11")
    );                                                                                         
}                                                                                              
Collapse
 
jasman7799 profile image
Jarod Smith

this has shown me how similar rust syntax can be to JavaScript syntax wow