Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • The collect step is unnecessary—you can chain iterator transformation operations such as map(), i.e. you can do map(...).sum().

  • This solution assumes s is entirely in ASCII, but Rust strings are UTF-8. For instance, find_short("ø") will return 2, because ø uses two bytes in UTF-8, but its length is only 1.

  • It will panic. However, the kata says String will never be empty, so it's a safe optimization.

  • If you're starting with an empty String, you might as well do String::new() instead of String::from("").

  • Victor-Sun, if you just do Count() on something, you'll count everything. However, Count() also has an overload that takes a predicate, which is basically a filter telling Count() whether or not to include an item in the count. You can think of Count(predicate) as shorthand for Where(predicate).Count() if you'd like.

    Thus, in the expression s => s, you're telling Count() to only count items if they are true.