79395728

Date: 2025-01-29 04:48:14
Score: 0.5
Natty:
Report link

I recently came across Range, Iterators in rust. Since Range expressions implement Iterator trait, the above one should be simple. Here's an example solution


 fn sum_from_zero( n: i32) -> i32 {
    (0..n).sum()
 }

or for closure/one-liner folks

let sum_from_zero = |n: i32| (0..n).sum::<i32>();

Rust Standard Library - Range

Rust Standard Library - Iterator

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: JayMGurav