← Back to challenges

Fauna in Chitwan National Park

JavaScriptHardlogiclanguage_fundamentalsregex

Instructions

Create a function that takes a string containing both the name and number of animals and plants that may or may not be found in Chitwan National Park. The function should return an array of tuples where the first element in the tuple is the animal name and the second element in the tuple is a number of that particular animal that is found in Chitwan National Park.

Animals Present in Chitwan National Park

animals = ["muggercrocodile", "one-hornedrhino", "python", "moth", "monitorlizard", "bengaltiger"]

Examples

faunaNumber("There are 24 one-hornedrhino, 50 python and 20000 mango.") ➞ [{"one-hornedrhino": 24}, {"python": 50}]
// Mango not present in animal array.

faunaNumber("There are 244 bengaltiger, 200 monitorlizard and 5000 apples.") ➞ [{"bengaltiger": 244}, {"monitorlizard": 200}]
// Apples not present in animal array.

Notes

  • Input contains name and number of both animals and plants.
  • If there is no match, return an empty array.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.