Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 realworld 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 :
Input: animals lion 'monkey', 'deer', 'snake', 'elephant'
Output:
Explanation: In this array, 'lion', 'deer', and 'elephant' have four legs.
Example :
Input: animals frog 'horse', 'spider', 'ant'
Output:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started