The Wide-Mouthed frog!

kata programming

قورباغه دهان گشاد علاقه خاصی به عادات غذایی موجودات دیگر دارد.

او فقط نمی تواند جلوی خودش را بگیرد که از موجوداتی که با آنها روبرو می شود نبپرسد که دوست دارند چه چیزی بخورند. اما، سپس او با تمساح روبرو می شود که فقط دوست دارد قورباغه های دهان پهن بخورد!

او زمانی که تمساح را دید، دهانش را خیلی کوچک کرد.

هدف شما در این کاتا این است که متد کامل اندازه دهان را ایجاد کنید. این متد یک پارامتر ورودی حیوان دارد که حیوان هایی هستند که با قورباغه با آنها مواجه می شود. اگر این متد یک تمساح (غیر حساس به حروف بزرگ و کوچک) داشته باشد باید عبارت small در غیر اینصورت wide را برگردانید.


The wide-mouth frog is particularly interested in the eating habits of other creatures.

He just can’t stop asking the creatures he encounters what they like to eat. But, then he meets the alligator who just LOVES to eat wide-mouthed frogs!

When he meets the alligator, it then makes a tiny mouth.

Your goal in this kata is to create complete the mouth_size method this method takes one argument animal which corresponds to the animal encountered by the frog. If this one is an alligator (case-insensitive) return small otherwise return wide.


public class WideMouthedFrog {
  public static String mouthSize(String animal) {
    return animal.equalsIgnoreCase("alligator") ? "small" : "wide";
  }
}
import java.util.Map;

public class WideMouthedFrog{
  private static final Map<String, String> values = Map.of("alligator", "small");
  
  public static String mouthSize(String animal){
     return values.getOrDefault(animal.toLowerCase(), "wide");
  }
}
function mouth_size($animal)
{
  return strtolower($animal) == "alligator" ? "small" : "wide";
}
function mouth_size($animal) {
    return !strcasecmp($animal, 'alligator') ? 'small' : 'wide';
}
function mouth_size($animal) {
   return preg_match("@alligator@i", $animal) ? 'small' : 'wide';
}
function mouth_size($animal) {
    return ['wide', 'small'][(int)(strtolower($animal) === 'alligator')];
}
function mouth_size($animal) {
  $re = '/alligator/i';
    if (!preg_match($re, $animal)) {
      return 'wide';
    } else {
      return 'small';
    }
}

دیدگاهتان را بنویسید