Problem · Array
List Games by Genre
Learn this problemProblem statement
Given parallel arrays gameNames and genres, return every game whose genre equals inputGenre. The value at genres[i] belongs to the game at gameNames[i].
For this exercise, assume comparisons are case-sensitive and return matching names in their original input order. If no game has inputGenre, return an empty array.
Function
listGamesByGenre(gameNames: String[], genres: String[], inputGenre: String) → String[]Examples
Example 1
gameNames = ["Cyber Quest","Battle Arena","Sky Adventure","Mystery World","Speed Racer"]genres = ["RPG","Action","Adventure","Puzzle","Racing"]inputGenre = "Action"return = ["Battle Arena"]Only Battle Arena has the genre Action.
Example 2
gameNames = ["A","B","C","D"]genres = ["Puzzle","RPG","Puzzle","Puzzle"]inputGenre = "Puzzle"return = ["A","C","D"]The matching games occur at indices 0, 2, and 3, so their names are returned in that order.
Constraints
0 <= gameNames.length <= 10000.genres.length == gameNames.length.- Every value in
gameNamesandgenresis non-empty. - Comparisons are case-sensitive.