Commit f08f5bfc authored by Christoph Häfner's avatar Christoph Häfner

Add square-n-sum

parent b62a7c93
fn square_sum(vec: Vec<i32>) -> i32 {
vec.iter().fold(0, |t,i| t + i*i)
}
fn square_sum(vec: Vec<i32>) -> i32 {
vec.iter().map(|x| x * x).sum()
}
#[test]
fn returns_expected() {
assert_eq!(square_sum(vec![1, 2]), 5);
assert_eq!(square_sum(vec![-1, -2]), 5);
assert_eq!(square_sum(vec![5, 3, 4]), 50);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment