2012-07-18 13:01:54 -05:00
|
|
|
fn sum_slice(x: &[int]) -> int {
|
|
|
|
let mut sum = 0;
|
2012-09-19 18:55:01 -05:00
|
|
|
for x.each |i| { sum += *i; }
|
2012-08-01 19:30:05 -05:00
|
|
|
return sum;
|
2012-07-18 13:01:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = @[1, 2, 3];
|
|
|
|
assert sum_slice(x) == 6;
|
|
|
|
}
|