cassidoo-newsletter/word-score/src/main.rs

22 lines
509 B

fn main() {
let highest = vec!["apple", "banana", "cherry", "date", "fig"]
.into_iter()
.map(|w| (w, score(w.to_owned())))
.reduce(|acc, b| {
if b.1 > acc.1 {
return b;
}
acc
})
.unwrap();
println!("{}: {}", highest.0, highest.1);
}
fn score(word: String) -> u32 {
word.chars()
.into_iter()
.map(|c| c.to_ascii_lowercase() as u32 - 96)
.sum::<u32>()
* word.len() as u32
}