Fundamentals
Strings
Code
Diff
  • fn minutes(mins: u32) -> String {
        format!("{}:{:02}", mins / 60, mins % 60)
    }
  • 1
    def minutes(mins):
    
    2
        return '{}:{:02}'.format(*divmod(mins, 60))
    
    1+
    fn minutes(mins: u32) -> String {
    
    2+
        format!("{}:{:02}", mins / 60, mins % 60)
    
    3+
    }
    
Strings

Take any string and return the last character.

If the string is empty, return nothing.

Code
Diff
  • fn last_char(string: &str) -> Option<char> {
        string.chars().rev().next()
    }
  • 1
    function lastChar(string) {
    
    2
      return string[string.length - 1];
    
    1+
    fn last_char(string: &str) -> Option<char> {
    
    2+
        string.chars().rev().next()
    
    33
    }