Question: Your task is to write a program that examines an array of different animals and determines how many of them have exactly four legs, simulating

Your task is to write a program that examines an array of different animals and determines how many of them have exactly four legs, simulating a real-world coding interview scenario.
Problem Details:
Problem Statement:
Given an array animals representing different animals in a forest, return the count of animals that have exactly four legs.
Input Format:
An array animals where each element is a string representing the name of an animal.
Output Format:
An integer representing the count of animals with four legs in the given array.
Examples:
Example 1:
Input: animals =['lion', 'monkey', 'deer', 'snake', 'elephant']
Output: 3
Explanation: In this array, 'lion', 'deer', and 'elephant' have four legs.
Example 2:
Input: animals =['frog', 'horse', 'spider', 'ant']
Output: 1
Explanation: Only 'horse' has four legs in this array.
List of Animals and Their Leg Counts:
Animals with Four Legs: 'lion', 'deer', 'elephant', 'horse', 'dog', 'cat'
Animals with Two Legs: 'monkey', 'parrot', 'ostrich'
Animals with No Legs: 'snake', 'worm'
Animals with Multiple Legs (more than four): 'spider', 'ant', 'centipede'
JAVASCRIPT

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!