Ad
Fundamentals
Strings
Logic

Write a function that returns string:

"Fizz" when the number is divisible by 3.

"Buzz" when the number is divisible by 5.

"FizzBuzz" when the number is divisible by 3 and 5.

Code
Diff
  • pub fn fizz_buzz(n: i32) -> String {
        match (n%3, n%5) {
            (0, 0) => "FizzBuzz".to_string(),
            (0, _) => "Fizz".to_string(),
            (_, 0) => "Buzz".to_string(),
            (_, _) => n.to_string()
        }
    }
    • public class FizzBuzz
    • {
    • public string GetOutput(int number)
    • {
    • if ((number % 3 == 0) && (number % 5 == 0))
    • return "FizzBuzz";
    • else if (number % 3 == 0)
    • return "Fizz";
    • else if (number % 5 == 0)
    • return "Buzz";
    • else return number.ToString();
    • }
    • pub fn fizz_buzz(n: i32) -> String {
    • match (n%3, n%5) {
    • (0, 0) => "FizzBuzz".to_string(),
    • (0, _) => "Fizz".to_string(),
    • (_, 0) => "Buzz".to_string(),
    • (_, _) => n.to_string()
    • }
    • }

GitHub

Jeddi's Profile Views

Code
Diff
  • pub fn make_uppercase(s: String) -> String {
        s.to_uppercase()
    }
    • function upperCase(s) {
    • //JUST DO IT
    • pub fn make_uppercase(s: String) -> String {
    • s.to_uppercase()
    • }

Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero digits.

Examples:

  1. n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3
  2. n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6
  3. n = 100, x = 5, y = 3 => false because 100 is not divisible by 3
  4. n = 12, x = 7, y = 5 => false because 12 is neither divisible by 7 nor 5

GitHub

Jeddi's Profile Views

Code
Diff
  • pub fn is_divisible(n: i32, x: i32, y:i32) -> bool {
        match (n % x == 0, n % y == 0) {
            (true, true) => true,
                       _ => false
        }
    }
    • function isDivisible(n, x, y) {
    • if (n % x === 0 && n % y === 0) {
    • return true
    • } else {
    • return false
    • }
    • pub fn is_divisible(n: i32, x: i32, y:i32) -> bool {
    • match (n % x == 0, n % y == 0) {
    • (true, true) => true,
    • _ => false
    • }
    • }

As the super Kumite that i forked, the task is to make a static function for create a new User instance (a.k.a constructor).


GitHub

Jeddi's Profile Views

Code
Diff
  • pub struct User {
        pub name: String,
        pub surname: String
    }
    
    impl User {
        pub fn New(n: String, s: String) -> Self {
            Self {
                name: n,
                surname: s
            }
        }
    }
    
    • function User(name, surname)
    • {
    • this.name = name
    • this.surname = surname
    • pub struct User {
    • pub name: String,
    • pub surname: String
    • }
    • impl User {
    • pub fn New(n: String, s: String) -> Self {
    • Self {
    • name: n,
    • surname: s
    • }
    • }
    • }